Description
Docs page(s)
https://eslint.org/docs/latest/rules/class-methods-use-this
What documentation issue do you want to solve?
The docs for class-methods-use-this
do a good job of explaining how to use the rule itself. But they don't include or link to any explanation of why you'd want to use it.
The docs also only suggest switching to a static function. That's not the only suggestible remediation. Oftentimes folks find standalone function declarations not associated with classes to be less overhead.
What do you think is the correct solution?
Perhaps the rule docs could have a section explaining something like:
- Upsides of using classes: encapsulation of state; reusability of logic; ...
- The downside of taking that overhead on when encapsulation & reusability can be done with lighter-weight constructs: e.g. standalone functions
- How class methods without
this
can be a sign of those downsides - 1-2 examples of refactors
If there was a great canonical resource on why many (not all) JavaScript programmers don't use classes, I would say we could at least link it there under Further Reading. I don't know of a great one.
Participation
- I am willing to submit a pull request for this change.
Additional comments
This is a fraught area to document. I don't want to suggest advising against classes at all. But I do want to suggest the page explains the reasons for and against enabling the rule.
This came out of a conversation on Bluesky: https://bsky.app/profile/joshuakgoldberg.com/post/3lrj3elwbc22b
Metadata
Metadata
Assignees
Labels
Type
Projects
Status