Skip to content

Detect unused private members in classes #14859

@TimvdLippe

Description

@TimvdLippe

What rule do you want to change?
no-unused-vars (arguably this could be a separate rule as well, something like no-unused-private-fields)
Does this change cause the rule to produce more or fewer warnings?
More
How will the change be implemented? (New option, new default behavior, etc.)?
New default behavior
Please provide some example code that this change will affect:

class MyClass {
  #unusedField = 5;
  #usedFieldOnlyInWrite = 42;
  #usedWhenReadingAndWriting = 500;
  someMethod() {
    this.#usedFieldOnlyInWrite = 42;
    this.#usedWhenReadingAndWriting += 1;
  }
  someOtherMethod() {
    return this.#usedWhenReadingAndWriting;
  }
}

What does the rule currently do for this code?
Nothing
What will the rule do after it's changed?
Report unused fields declared in a class. In the above example, it should report that both #unusedField and #usedFieldOnlyInWrite are unused. This should be possible, as private fields are only concerned in a particular class context, so you can collect all fields in a class, iterate through all usages and mark does that are never read as unused.
Are you willing to submit a pull request to implement this change?
I would be able to give it a go, but I am not sure how difficult this would be.

Metadata

Metadata

Assignees

Labels

acceptedThere is consensus among the team that this change meets the criteria for inclusionarchived due to ageThis issue has been archived; please open a new issue for any further discussionfeatureThis change adds a new feature to ESLintruleRelates to ESLint's core rules

Type

No type

Projects

Status

Complete

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