跳转到内容

noUnusedPrivateClassMembers

此内容尚不支持你的语言。

Diagnostic Category: lint/correctness/noUnusedPrivateClassMembers

Since: v1.3.3

Sources:

Disallow unused private class members

Private class members that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such class members take up space in the code and can lead to confusion by readers.

class OnlyWrite {
#usedOnlyInWrite = 5;
method() {
this.#usedOnlyInWrite = 212;
}
}
code-block.js:2:3 lint/correctness/noUnusedPrivateClassMembers  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━

This private class member is defined but never used.

1 │ class OnlyWrite {
> 2 │ #usedOnlyInWrite = 5;
^^^^^^^^^^^^^^^^
3 │
4 │ method() {

Unsafe fix: Remove unused declaration.

1 1 class OnlyWrite {
2 - ··#usedOnlyInWrite·=·5;
3 2
4 3 method() {

class TsBioo {
private unusedProperty = 5;
}
code-block.ts:2:12 lint/correctness/noUnusedPrivateClassMembers  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

This private class member is defined but never used.

1 │ class TsBioo {
> 2 │ private unusedProperty = 5;
^^^^^^^^^^^^^^
3 │ }
4 │

Unsafe fix: Remove unused declaration.

1 1 class TsBioo {
2 - ···private·unusedProperty·=·5;
3 2 }
4 3

class TsBioo {
private unusedMethod() {}
}
code-block.ts:2:12 lint/correctness/noUnusedPrivateClassMembers  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━

This private class member is defined but never used.

1 │ class TsBioo {
> 2 │ private unusedMethod() {}
^^^^^^^^^^^^
3 │ }
4 │

Unsafe fix: Remove unused declaration.

1 1 class TsBioo {
2 - ···private·unusedMethod()·{}
3 2 }
4 3

class UsedMember {
#usedMember = 42;
method() {
return this.#usedMember;
}
}