Skip to content

no-instance-methods-without-this

Report instance methods that never use this or super.

This rule checks non-static class methods with kind: "method". Getters, setters, constructors, and static methods are ignored.

By default it checks public, protected, and private methods. If a method body never touches this or super, the rule reports it.

The scan walks the whole method body, including nested functions. If a nested callback uses this, the method is treated as using this too.

All three options default to true.

  • checkPublic
  • checkProtected
  • checkPrivate
eslint.config.ts
import plugin from "eslint-plugin-cease-nonsense";
export default [
{
plugins: { "cease-nonsense": plugin },
rules: {
"cease-nonsense/no-instance-methods-without-this": [
"error",
{ checkPrivate: false, checkProtected: true, checkPublic: true },
],
},
},
];
Incorrect
class MathSystem {
private calculate(x: number): number {
return x * x;
}
}
Correct
function calculate(x: number): number {
return x * x;
}
class MathSystem {
public run(value: number): number {
return calculate(value);
}
protected log(): void {
print(this);
}
}