classMethodsThis
Reports class methods that do not use
this.
✅ This rule is included in the ts stylistic presets.
Class methods that don’t use this are often better suited as static methods or standalone functions.
Instance methods that don’t access instance state can be misleading and suggest a design issue.
Examples
Section titled “Examples”class Calculator { add(a: number, b: number) { return a + b; }}class Formatter { format(value: string) { return value.trim().toLowerCase(); }}class Handler { get type() { return "default"; }}class Processor { handler = () => { return Math.random(); };}class Calculator { add(a: number, b: number) { return this.precision(a + b); }}class Calculator { static add(a: number, b: number) { return a + b; }}function add(a: number, b: number) { return a + b;}class Counter { private count = 0;
get value() { return this.count; }}class Base { method(): void {}}
class Derived extends Base { override method() { console.log("overridden"); }}interface Handler { handle(): void;}
class MyHandler implements Handler { handle() { console.log("handled"); }}Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”If your codebase has many classes that implement external interfaces or extend base classes where methods are expected to exist without using this, this rule may produce false positives.
Some frameworks require instance methods for dependency injection or other patterns even when they don’t use this.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.