📎 Implement noMagicNumbers
- eslint/no-magic-numbers
, typescript-eslint/no-magic-numbers
#4333
Labels
A-Linter
Area: linter
L-JavaScript
Language: JavaScript and super languages
S-Help-wanted
Status: you're familiar with the code base and want to help the project
Description
Implement eslint/no-magic-numbers and typescript-eslint/no-magic-numbers.
Want to contribute? Lets you know you are interested! We will assign you to the issue to prevent several people to work on the same issue. Don't worry, we can unassign you later if you are no longer interested in the issue! Read our contributing guide and analyzer contributing guide.
See the related discussion for context.
The ESLint rule has many options.
I suggest implementing a single option
ignoreIntegers
(See theOptions
section) for the time being.Here are the exceptions we should bake in:
ignore assignment to constant-like variables, i.e.
const
,var
, and static class propertiesIgnore common numbers
We should always ignore
0
/0n
/0.
, and maybe2
/2n
,1
/1n
, and-1
/-1n
.Should we ignore more integers?
Ignore integer indexing (corresponds setting ESLints'
ignoreArrayIndexes
andignoreTypeIndexes
totrue
)Ignore integer Enum values (corresponds setting ESLint's
ignoreEnums
totrue
)ignore numeric types (corresponds setting ESLint's
ignoreNumericLiteralTypes
totrue
)Ignore integer binary operations
Others?
Options
We could introduce an
ignoreIntegers
option (turned off by default).When the option is set to true, all integers values are ignored:
The text was updated successfully, but these errors were encountered: