Skip to content

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.

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();
};
}

This rule is not configurable.

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.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.