Skip to content

Docs: Add explanation of "why" to class-methods-use-this #19852

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

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:

  1. Upsides of using classes: encapsulation of state; reusability of logic; ...
  2. The downside of taking that overhead on when encapsulation & reusability can be done with lighter-weight constructs: e.g. standalone functions
  3. How class methods without this can be a sign of those downsides
  4. 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

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusiondocumentationRelates to ESLint's documentation

Type

No type

Projects

Status

Ready to Implement

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    pFad - Phonifier reborn

    Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

    Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


    Alternative Proxies:

    Alternative Proxy

    pFad Proxy

    pFad v3 Proxy

    pFad v4 Proxy