Repository navigation
Conversation
… as writes ESLint records a `var` initializer as a write reference. Oxc stores that initializer as another declaration of the same symbol, so `var x; var x = k` looked unassigned. Treat a redeclaration with an initializer, or a `for`-`in` / `for`-`of` binding, as a write. Co-authored-by: Rahul Kashyap <itisrmk@users.noreply.github.com>
Contributor
Author
|
Hi! Could a maintainer approve the CI workflows for this PR when you have a moment? Thanks. |
…ars-redeclared-var Co-Authored-By: Rahul Kashayp <rahulmkashyap@gmail.com> # Conflicts: # crates/oxc_linter/src/rules/eslint/no_unassigned_vars.rs
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #27982 (the
no-unassigned-varshalf; theno-useless-concathalf is #27984).The rule only counts
reference.is_write()as an assignment. In Oxc avarinitializer isn't a write reference: it's another declaration of the same symbol. Sovar x; var x = k; return x;(and the reverse order, and theifblock case from the issue) were reported as alwaysundefined, while ESLint, which records initializers as write references, reports nothing.The rule now looks at the symbol's redeclarations and treats one as a write when its declarator has an initializer, or when it is the loop variable of a
for-in/for-of. Function declarations and parameters still don't count as writes, which matches ESLint.Tests
f,g, andh, plus the same pattern within one statement (both orders), inside a block, withvar { x }/var [x], and as afor-in,for-of, andfor (var x = 1;;)head.var x; var x, avarafter a function declaration of the same name, avarafter a parameter of the same name, andvar { y = x }(readsx, doesn't assign it).cargo test -p oxc_linter --libandcargo lint -p oxc_linter --lib --tests(warnings denied) pass locally.One existing difference I left alone: a lone
for (var x;;) { return x; }is still not reported, because the rule already skips every declarator in aforhead. ESLint does report it. Happy to follow up on that separately if you want it.AI disclosure
I used an AI coding assistant to help write this change and its tests. I reviewed the diff and the snapshot output before opening the PR.