-
-
Notifications
You must be signed in to change notification settings - Fork 781
fix(linter/no-unused-vars): panic when variable is redeclared as function in same scope #11280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(linter/no-unused-vars): panic when variable is redeclared as function in same scope #11280
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
CodSpeed Instrumentation Performance ReportMerging #11280 will not alter performanceComparing Summary
|
9e612d4 to
c69afcd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a panic in the no-unused-vars rule when a variable is redeclared as a function in the same scope by iterating over symbol_redeclarations to find the correct function declaration, and adds a test case to cover this scenario.
- Handle redeclarations in
usage.rsto select the function’s scope when a variable and function share a name - Add a
test_jstest intests/oxc.rsfor the redeclaration case
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs | Added logic to inspect symbol_redeclarations and select the function container scope |
| crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs | Introduced test_js covering redeclared function scenario |
Comments suppressed due to low confidence (4)
crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs:755
- [nitpick] The variable name
declarationis a bit generic and shadows the outer context; rename it to something likefunction_declfor clarity.
let declaration = redeclarations.iter().find(|decl| decl.flags.is_function()).unwrap();
crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs:760
- There's a duplicated "or" in the debug message (
"or or"); please remove the extra word.
"Found a function call or or new expr reference on a node flagged as a function or class, but the symbol's declaration node has no scope id. It should always be a container."
crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs:1296
- [nitpick] The test name
test_jsis quite generic; consider renaming it to something more descriptive liketest_redeclared_function_scope.
fn test_js() {
crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs:1299
- You might also add a test for the reverse order (e.g.
var a; function a() { a(); }) to ensure both declaration patterns are covered.
"export function promisify() { var fn; function fn() {}; return fn; }",
c69afcd to
21d06cf
Compare
Merge activity
|
…tion in same scope (#11280) * close: #11215 * close: #11234 ```js var a; function a() { a() } ``` The above code is legal; in this case, the symbol_declaration points to `var a` rather than `function a`a because the current implementation handles them in order they declared, thus we need to iterate over `symbol_redeclarations` to find the function's node id.
21d06cf to
19772e5
Compare
## [0.17.0] - 2025-05-30 - ead5309 linter: [**BREAKING**] Remove react from default plugin set (#11382) (camc314) ### Features - 2d25bd8 linter: Remove `unicorn/no-for-loop` over `typescript/prefer-for-of` (#11354) (camc314) - bbb7eb1 linter: Add auto-fix to react/forward-ref-uses-ref (#11342) (yefan) - 590c27b linter: Add auto-fix to unicorn/no-await-expression-member (#11306) (yefan) - 7824f01 linter: Implement suggestion for `jsx/no-useless-fragment` (#10800) (Cam McHenry) - 2083d33 linter/language_server: Add second editor suggestion for `react/forward-ref-uses-ref` (#11375) (Sysix) ### Bug Fixes - f6424dd linter: Reflect react plugin is disabled by default in cli (#11397) (camc314) - 25ecbfe linter: Remove use of `FrameworkFlags::React` to decide whether rules should run (#11383) (camc314) - 0d240e4 linter: False positive in react/exhaustive-deps with default formal parameter (#11395) (camc314) - c91697e linter: Fix panic in multi byte char in `TryFrom` aria (#11350) (camc314) - 9798ef1 linter: Stack overflow in no-async-endpoint-handlers (#11317) (camc314) - 348ad97 linter: Skip no-unused-vars on astro files (#11303) (camc314) - 183d7f0 linter: Make `jest/no-large-snapshots` error easier to comprehend (#11294) (Ulrich Stark) - 4e606a5 linter: Improve `jest/no-large-snapshots` (#11291) (Ulrich Stark) - 14f790f linter: Improve `jest/no-restricted-matchers` (#11292) (Ulrich Stark) - a2c82be linter/block-scoped-var: Better diagnostic messages (#11290) (DonIsaac) - 19772e5 linter/no-unused-vars: Panic when variable is redeclared as function in same scope (#11280) (Dunqing) - 7af5bb1 oxc_language_server: Include save option for text document sync capability (#11297) (Nicholas Rayburn) ### Performance - 0ed6c1a language_server: Use `Arc<RwLock>` instead of `Mutex` for workspace workers (#11328) (Sysix) - a0ee946 linter: Reduce code size in `globals` (#11333) (shulaoda) - c90c5e9 linter/no-unused-vars: Simplify checking self call usage (#11281) (Dunqing) ### Documentation - eae51ca linter: Clarify jsdoc/check-tag-names configuration (#11394) (Rägnar O'ock) - cd354d4 oxlint: Remove incorrect doc comment (#11326) (camc314) ### Refactor - 42738f0 linter: Shorten code of match arms (#11389) (Ulrich Stark) - 8a34447 linter: Improve `unicorn/text-encoding-identifier-case` (#11386) (shulaoda) - eaa605e linter: Avoid some `Arc::clone` in linter runtime (#11388) (Boshen) - 1cd8b9c linter: Fixes in `react/forward-ref-uses-ref` are suggestions (#11376) (Sysix) - 50ef691 linter: Add `diagnostics_with_multiple_fixes` to `LintContext` (#11357) (Sysix) - 606bb34 linter: Accept `PossibleFixes` instead of `Fix` for `Messages` (#11295) (Sysix) - 042a3f3 linter: Use `PossibleFixes` instead of `Option<Fix>` (#11284) (Sysix) - ffcfb46 linter: Improve `unicorn/throw-new-error` (#11364) (shulaoda) - 8fb55c3 linter: Cleanup docs and simplify code of `eslint/no-fallthrough` (#11331) (Ulrich Stark) - e2f0f0a linter: Improve docs and simplify code of `eslint/no-duplicate-imports` (#11320) (Ulrich Stark) - b53b053 linter: Simplify accessing span of NameSpan (#11305) (Ulrich Stark) - 4bc2650 linter: Improve `eslint/no-void` (#11285) (shulaoda) ### Styling - 49b664c linter: Remove needless newline in `declare_oxc_lint` (#11400) (camc314) ### Testing - c4f64aa linter: Explicitly disable correctness for clarity (#11327) (camc314) - a404b2c linter: `eslint/no-duplicate-imports` shouldn't report the same span (#11324) (Ulrich Stark) Co-authored-by: camc314 <[email protected]>

symbol_declarationswhen a function is found after a var #11234The above code is legal; in this case, the symbol_declaration points to
var arather thanfunction aa because the current implementation handles them in order they declared, thus we need to iterate oversymbol_redeclarationsto find the function's node id.