Allow the option to disable magic number warnings within arrays #11383
Labels
archived due to age
This issue has been archived; please open a new issue for any further discussion
auto closed
The bot closed this issue
enhancement
This change enhances an existing feature of ESLint
evaluating
The team will evaluate this issue to decide whether it meets the criteria for inclusion
rule
Relates to ESLint's core rules
What rule do you want to change?
no-magic-numbers
(source, docs)Does this change cause the rule to produce more or fewer warnings?
Fewer (if enabled as option). No changes by default.
How will the change be implemented? (New option, new default behavior, etc.)?
I imagine this as an extra boolean option, e.g.
ignoreArrayElements
, that defaults totrue
(the current behaviour).You could also specify a max array length. e.g. short arrays (which are more explicit) are ignore by the rule, long arrays are not.
Please provide some example code that this change will affect:
This is the code that made the need for the new option apparent:
This scenario could be avoided by destructuring the array, but that feels inelegant at the moment. If you had a longer array of indexes that you wanted to loop over this would get even worse:
What does the rule currently do for this code?
Disallows ambiguously specified (magic) numbers from being written without a labelled variable. More specifically for this issue, the rule also raises a warning/error for magic numbers within arrays.
What will the rule do after it's changed?
Disable warnings for magic numbers found within arrays.
Are you willing to submit a pull request to implement this change?
Not unless absolutely necessary
The text was updated successfully, but these errors were encountered: