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: radix rule crash on disabled globals #12824
Conversation
It seems that the rules are not consistent on what to do if the targeted global doesn't exist as an ESLint global variable. Some rules do check unresolved references with the targeted name, some rules don't. I'm not sure what's better to do in this rule, |
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.
LGTM Thanks. 👍
It looks definitely a bug.
Some rules do check unresolved references with the targeted name, some rules don't.
I checked all other rules which use astUtils.getVariableByName()
. And it seems radix
is the only one which does not check unresolved references.
checked rules - using astUtils.getVariableByName()
- symbol-description
- no-catch-shadow
- no-undef-init
- no-label-var
- no-eval
- no-console
- no-regex-spaces
- no-shadow
- no-unmodified-loop-condition
- prefer-const
@mdjermanovic @yeonjuan Really appreciate you two exploring all these inconsistencies. Inconsistency between rules is definitely confusing, and it's great to standardize our approach as much as possible! Some other thoughts on this topic as we explore making things more consistent (not necessarily relevant to this PR specifically):
|
@yeonjuan I found It looks like search won't be helpful enough, we'll have to check from the list of all rules :) |
Just to mention some thoughts, although completely unrelated to this PR and global variables.
The 5 naming convention rules are a good candidate for this: I was thinking about a proposal for a new rule to combine them all (or at least to unify or consolidate the logic in the existing rules if it wouldn't be a breaking change for some of them), but it will take some time to prepare, mostly to find out how to retain all the existing features. One rule, or at least shared logic in one place, should be also helpful for the maintenance. It seems that the hard part is to determine which of the identifiers nodes should be checked and which shouldn't. Once it is known, the easy part is to check whether the variable names have appropriate length, have underscores, are blacklisted etc. |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
Online Demo Link (v6.8.0 actual)
What did you expect to happen?
Not to crash.
What actually happened? Please include the actual, raw output from ESLint.
What changes did you make? (Give an overview)
Fixed the
radix
rule to check if the global variablesparseInt
/Number
exist.If not, the rule will not crash (and also will not report errors).
Is there anything you'd like reviewers to focus on?