Skip to content

Commit

Permalink
fix(no-unused-vars): consider functions within conditional expression…
Browse files Browse the repository at this point in the history
…s usable (#6553)
  • Loading branch information
eventualbuddha authored Oct 15, 2024
1 parent 448388a commit b9d7c5f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/allowed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ impl<'s, 'a> Symbol<'s, 'a> {
| AstKind::ArrayExpressionElement(_)
| AstKind::ExpressionArrayElement(_)
| AstKind::ArrayExpression(_)
// a ? b : function foo() {}
// Only considered used if the function is the test or the selected branch,
// but we can't determine that here.
| AstKind::ConditionalExpression(_)
=> {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ fn test_vars_simple() {
",
None,
),
("console.log(function a() {} ? b : c)", None),
("console.log(a ? function b() {} : c)", None),
("console.log(a ? b : function c() {})", None),
];
let fail = vec![
("let a = 1", None),
Expand Down

0 comments on commit b9d7c5f

Please sign in to comment.