-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Description
What rule do you want to change?
class-methods-use-this
What change do you want to make?
Generate fewer warnings
How do you think the change should be implemented?
A new option
Example code
interface Base {
method(): void;
}
class Derived implements Base {
method() {}
property = () => {};
}
What does the rule currently do for this code?
Reports on the method
and property
for not using this
.
This is sub-optimal because some projects prefer organizing code with classes implementing interfaces even when implementing methods don't always need to use this
.
What will the rule do after it's changed?
If the user has enabled a new ignoreClassesThatImplementAnInterface
option to...
'all'
: ignore all classes that implement an interface- This is
true
in the typescript-eslint rule for legacy reasons, but IMO it's odd having aboolean | string
option
- This is
'public-fields'
: ignore only the public fields of classes that implement an interface
Either way, the provided snippet would not receive any lint reports.
Participation
- I am willing to submit a pull request to implement this change.
Additional comments
It would be nice to know which methods are actually defined on the base interface. But doing so would require typed linting, and not even the typescript-eslint extension rule is typed.
Following #19498, this feature request corresponds to the existing typescript-eslint rule option: https://typescript-eslint.io/rules/class-methods-use-this/#ignoreclassesthatimplementaninterface
Metadata
Metadata
Assignees
Labels
Type
Projects
Status