Skip to content

Commit

Permalink
fix(linter/no-unused-vars): false positive when a variable used as a …
Browse files Browse the repository at this point in the history
…computed member property (#5722)

close: #5671
  • Loading branch information
Dunqing committed Sep 12, 2024
1 parent 748e6f8 commit e9c084a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ fn test_vars_simple() {
",
None,
),
(
"
const a = 0
obj[a]++;
",
None,
),
];
let fail = vec![
("let a = 1", None),
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,13 @@ impl<'s, 'a> Symbol<'s, 'a> {
// a = yield a // <- still considered used b/c it's propagated to the caller
// }
AstKind::YieldExpression(_) => return false,
AstKind::MemberExpression(MemberExpression::ComputedMemberExpression(computed)) => {
// obj[a]++;
// ^ the reference is used as property
if computed.expression.span().contains_inclusive(ref_span) {
return false;
}
}
_ => { /* continue up tree */ }
}
}
Expand Down

0 comments on commit e9c084a

Please sign in to comment.