no-instance-methods-without-this
Report instance methods that never use this or super.
Rule details Problem
Section titled “Rule details ”ProblemThis 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.
Options
Section titled “Options”All three options default to true.
checkPubliccheckProtectedcheckPrivate
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 }, ], }, },];Examples
Section titled “Examples” 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); }}Related rules
Section titled “Related rules” require-module-level-instantiation Another rule that pushes reusable logic toward module scope.