# Biome said a method never used this, but its default parameter did

You write a class method, run the linter, and it tells you the method never uses `this`, so it could be `static`. You look, and there it is: `this.defaultHeader`, right in the method's first line. The linter just didn't look there.

That's what luisfi-dev reported in [issue #13084](https://github.com/biomejs/biome/issues/13084) for Biome, a tool that formats and checks web code. I picked it up, and the fix was merged in [biomejs/biome#13098](https://github.com/biomejs/biome/pull/13098).

## The rule and what it's for

A linter is a program that reads your code without running it and points out likely mistakes or style problems. Each check is called a rule. Biome's `useThisInClassMethods` rule, which mirrors ESLint's `class-methods-use-this`, looks for class methods that never use `this`.

In JavaScript, `this` inside a method means "the object this method was called on", much like `self` in Python. A method that never touches `this` doesn't need an object at all. It could be `static`, meaning it belongs to the class itself rather than to each object, or it could move out of the class. That's a fair hint, as long as the rule is right about `this`.

Here is the code from the issue, trimmed from their playground:

```ts
class Console {
  defaultHeader: string

  print(content: string, header = this.defaultHeader) {
    console.log(`=== ${header.toUpperCase()} ===`);
    // trimmed
  }
}
```

The `header = this.defaultHeader` part is a default parameter value: if you call `print("hi")` without a header, JavaScript fills in `this.defaultHeader`. The method body itself never says `this`. But the default does, and as a comment in their playground pointed out, making this method `static` would make that `this` stop working.

## Why the rule missed it

Think of a method as a recipe card. At the top there's the ingredient list, which is the parameters. Below it are the steps, which is the body. The rule only read the steps. If the ingredient list said "a cup of whatever's in your own fridge", it never noticed you needed your own fridge.

The default value runs whenever the method is called without that argument, and it runs with the same `this` as the body. So it counts. But the rule only searched one place:

```rust
Self::JsMethodClassMember(member) => {
    Some(uses_lexical_this(member.body().ok()?.syntax()))
}
```

Biome is written in Rust. This line says: for a method, look for `this` inside its body, and nowhere else. Setters, the methods that run when you assign to a property, worked the same way. A `this` in the parameter list was never seen.

## The fix

Methods and setters now look at their parameters as well as their body:

```rust
// A parameter's default value runs with the method's `this`.
Self::JsMethodClassMember(member) => Some(
    uses_lexical_this(member.parameters().ok()?.syntax())
        || uses_lexical_this(member.body().ok()?.syntax()),
),
```

`||` means "or": if either the parameters or the body use `this`, the method uses `this`.

The rule also checks class fields whose value is a function, like `arrowField = (value = 1) => value`. Those got the same change, so `arrowField = (value = this.defaultHeader) => value` now counts as using `this` too.

I passed the parameters and the body separately on purpose, rather than the whole method. That way the rules the body already followed apply to defaults too. JavaScript has two kinds of function. An arrow function (`() => ...`) borrows `this` from around it. A regular `function` gets its own `this`. So `read(callback = () => this.defaultHeader)` uses the method's `this` and is fine, while `read(callback = function () { return this.value; })` doesn't, and is still reported.

TypeScript adds one more trap. You can write `method(this: ThisParameterOnly, value = 1)`, where `this:` only declares what type `this` has. It isn't a use, so that method is still reported. The test files cover each of these.

## What review changed

Biome runs CodeRabbit, a review bot, on its PRs. One of its notes, marked minor, found a real hole in my change.

Parameters can have decorators. A decorator is the `@something(...)` you can put in front of a parameter in TypeScript, to attach extra behaviour. Going back to the recipe card, it's like a sticker the printer put on the card when the cookbook was made. It's on the card, but it was applied long before anyone cooked.

That's how decorators work too: their code runs once, when the class is created, not when the method is called. So for a class built inside another function, `method(@decorate(this.key) value: unknown) { return value; }` would now be treated as using `this`, even though the method never uses its own `this`. My parameter check walked the whole parameter list, decorators included.

The fix was to treat a decorator like the places the rule already skipped, such as a class nested inside the method:

```rust
if AnyJsClass::can_cast(node.kind())
    || JsStaticInitializationBlockClassMember::can_cast(node.kind())
    // A parameter decorator runs when the class is defined, not with the member's `this`.
    || JsDecorator::can_cast(node.kind())
    // trimmed: the existing check for nested non arrow functions
```

When the search reaches a decorator, it no longer looks inside. Two more test files cover it. One has methods whose only `this` is inside a decorator, and they're reported. The other has a decorator plus a real default, `method(@decorate(this.key) value = this.fallback)`, and that one is fine.

Run on the main branch without the fix, the two "valid" test files fail. Without just the decorator part, the decorator "invalid" file fails. With the whole PR, all 18 cases pass.

Right after the bot's review, dyc3 asked me to follow the PR template, which I hadn't filled in. Fair point, so I did. dyc3 approved and merged it on 11 November 2026, the same day I opened it. Thanks, dyc3!

## What I'm keeping from this one

Whether a method uses `this` depends on when each piece of code runs. Where it's written can fool you: defaults run with the call, and decorators run with the class.

When you widen what a check looks at, ask what else you just pulled in. Going from the body to the parameters pulled in decorators.

And fill in the template before anyone reads your PR. It's there so reviewers don't have to ask.

Have you hit a lint rule that was right about the body and wrong about the signature? I'd like to hear about it.

