Skip to content

noUnusedPrivateClassMembers

诊断类别:lint/correctness/noUnusedPrivateClassMembers

¥Diagnostic Category: lint/correctness/noUnusedPrivateClassMembers

自从:v1.3.3

¥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.

¥Examples

¥Invalid

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

¥Valid

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

¥Related links