A class method never uses this, so it does not need an instance

tx0/ts:method-without-thisstrictwarningsmell

What it finds

A method that never uses this does not depend on its instance; callers still need one to reach it. A function of its own, or a static method, says that it works on its arguments alone and can be used and tested without an object.

Reported are non-static methods with a body that mention neither this nor super, directly or in arrow functions, which share them. Methods of classes that extend or implement something, overriding or decorated methods, and abstract ones are left alone, since their signature is dictated from elsewhere.

From the rule's source, method_without_this.rs.

Example from the rule's tests
export class Formatter {  prefix = ">";  format(text: string) {    return this.prefix + text;  }  pad(text: string) {tx0 reports: pad never uses this    return " " + text;  }  later() {    return () => this.prefix;  }  static make() {    return new Formatter();  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:method-without-this" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/ts:method-without-this] reason="..."

tx0 explain tx0/ts:method-without-this shows the same in the terminal. Found a false positive? Report it.