Skip to content

Commit 290b3f5

Browse files
committed
fix(linter/no-unused-private-class-members): fix false positive with await expression
1 parent 70d6995 commit 290b3f5

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ fn is_value_context(kind: &AstNode, semantic: &Semantic<'_>) -> bool {
232232
| AstKind::TSInstantiationExpression(_)
233233
| AstKind::TSNonNullExpression(_)
234234
| AstKind::TSTypeAssertion(_)
235-
| AstKind::UpdateExpression(_) => {
235+
| AstKind::UpdateExpression(_)
236+
| AstKind::AwaitExpression(_) => {
236237
is_value_context(semantic.nodes().parent_node(kind.id()), semantic)
237238
}
238239

@@ -452,6 +453,7 @@ fn test() {
452453
r"class C { #field = 1; static { const obj = new C(); console.log(obj.#field); } }",
453454
r"class C { #method() { return 42; } static { const obj = new C(); obj.#method(); } }",
454455
r"class C { #field = 1; static { const getField = obj => { return obj.#field; }; } }",
456+
r"export class Database<const S extends idb.DBSchema> { readonly #db: Promise<idb.IDBPDatabase<S>>; constructor(name: string, version: number, hooks: idb.OpenDBCallbacks<S>) { this.#db = idb.openDB<S>(name, version, hooks); } async read() { let db = await this.#db; } }",
455457
];
456458

457459
let fail = vec![
@@ -597,6 +599,7 @@ fn test() {
597599
}
598600
}
599601
}",
602+
r"class Foo { #awaitedMember; async method() { await this.#awaitedMember; } }",
600603
];
601604

602605
Tester::new(NoUnusedPrivateClassMembers::NAME, NoUnusedPrivateClassMembers::PLUGIN, pass, fail)

crates/oxc_linter/src/snapshots/eslint_no_unused_private_class_members.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,3 +160,11 @@ source: crates/oxc_linter/src/tester.rs
160160
· ──────────────────────────────
161161
3
162162
╰────
163+
164+
⚠ eslint(no-unused-private-class-members): 'awaitedMember' is defined but never used.
165+
╭─[no_unused_private_class_members.tsx:2:13]
166+
1 │ class Foo {
167+
2 │ #awaitedMember = Promise.resolve(42);
168+
· ──────────────
169+
3async method() {
170+
╰────

0 commit comments

Comments
 (0)