-
-
Notifications
You must be signed in to change notification settings - Fork 519
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
📎 Implement noMagicNumbers
- eslint/no-magic-numbers
, typescript-eslint/no-magic-numbers
#4333
Comments
@fellipeutaka Could you add a comment on this task. I am not able to assign you to the task if you don't participate here. |
Oh, sorry. I'm ready to contribute to this task :) |
No problem. I was not aware of this limitation on GitHub ^^ |
Hey folks, Any updates on this one? CC: @Conaclos, @fellipeutaka, @ematipico |
@kerolloz do you want to help and implement it? |
Yup sure, I'd love to. |
Hey, I wanted to apologize for the delay in updating this task. After some time using the In my experience, the best way to prevent magic numbers in a codebase is through consistent and thorough code reviews. They allow for context-specific discussions and ensure that meaningful constants or descriptive variable names are used where necessary. To @kerolloz: best of luck with this task! It’s an exciting challenge, and I’m sure your implementation will bring great value to the community. Feel free to reach out if you need any insights or suggestions from my experience with the rule. Looking forward to seeing your work! |
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: