Skip to content

classMethodsThis

Reports class methods that do not use this.

✅ This rule is included in the ts stylistic and stylisticStrict 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
class Calculator
Calculator
{
Calculator.add(a: number, b: number): number
add
(
a: number
a
: number,
b: number
b
: number) {
return
a: number
a
+
b: number
b
;
}
}
class
class Formatter
Formatter
{
Formatter.format(value: string): string
format
(
value: string
value
: string) {
return
value: string
value
.
String.trim(): string

Removes the leading and trailing white space and line terminator characters from a string.

trim
().
String.toLowerCase(): string

Converts all the alphabetic characters in a string to lowercase.

toLowerCase
();
}
}
class
class Handler
Handler
{
get
Handler.type: string
type
() {
return "default";
}
}
class
class Processor
Processor
{
Processor.handler: () => number
handler
= () => {
return
var Math: Math

An intrinsic object that provides basic mathematics functionality and constants.

Math
.
Math.random(): number

Returns a pseudorandom number between 0 and 1.

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 ❤️‍🔥 around the world by the Flint team and contributors.