fix: avoid prefer-numeric-literals false positive for shadowed globals#21047
Merged
mdjermanovic merged 1 commit intoJul 3, 2026
Merged
Conversation
|
|
✅ Deploy Preview for docs-eslint canceled.
|
|
Hi @koreahghg!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the pull request title to match this format, as we use it to generate changelogs and automate releases.
To Fix: You can fix this problem by clicking 'Edit' next to the pull request title at the top of this page. Read more about contributing to ESLint here |
Member
|
Thanks for the PR. I can reproduce it in the Playground, so marking this as accepted, but next time please use our PR template. |
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.
Summary
prefer-numeric-literalsdetects calls toparseInt()/Number.parseInt()purely by identifier/property name, without checking whetherparseIntorNumberactually resolve to the global built-ins. If either is shadowed by a local binding, the rule still reports it, and its--fixautofix replaces the call with a numeric literal — silently changing the program's behavior since the call is no longer to the (unrelated) shadowed binding at all.--fixturns this into:Sibling rules
radixanduse-isnanwere already fixed for the same class of bug (see #21044 and #20958), by checkingsourceCode.isGlobalReference(...)in addition to the name-based check. This PR applies the same fix toprefer-numeric-literals.Test plan
validtest cases for shadowedparseInt(both as a parameter and avardeclaration) and shadowedNumber(member access form)npm test -- tests/lib/rules/prefer-numeric-literals.jspasses (91 tests)Linter#verify/verifyAndFixthat the false positive and the destructive autofix are both gone after the fix