-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Rule Request: No magic number #4024
Comments
This is a good idea. One small comment, I think you should edit the title to |
Done! Thanks |
About item 4: what do you think of having a configuration to allow some numbers? 0 and 1 are so common and understandable that this rule without configuration may trigger false positives.
Using that link you provided as an example, eslint accepts an array of ignored numbers. That way, you can have a rule |
Alternatively, 0 and 1 could just be ignored by default since they are so widely used in all kinds of contexts. Same for 0.0 and 1.0 probably. A configuration to ignore arbitrary numbers in a whole project or a subset of files might not turn out to be very useful. Why would someone like to ignore "57", for example? That said, I would not make the rule configurable at first until someone comes up with a very good example showing that it's really necessary. |
Should be closed since |
New Issue Checklist
New rule request
Please describe the rule idea, format
this issue's title as
Rule Request: [Rule Name]
and describe:Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
https://eslint.org/docs/latest/rules/no-magic-numbers
Provide several examples of what would and wouldn't trigger violations.
Basically, when you use a number without giving it some context.
Should the rule be configurable, if so what parameters should be configurable?
No
Should the rule be opt-in or enabled by default? Why?
It should be optional
The text was updated successfully, but these errors were encountered: