-
-
Notifications
You must be signed in to change notification settings - Fork 793
feat(biome_js_analyse): added new rule noMagicNumbers #6562
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
feat(biome_js_analyse): added new rule noMagicNumbers #6562
Conversation
🦋 Changeset detectedLatest commit: 86af259 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
7f0b76c to
8a306d7
Compare
CodSpeed Performance ReportMerging #6562 will not alter performanceComparing Summary
|
ematipico
left a comment
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.
Haven't checked the code yet. I left a couple of things to address
Co-authored-by: Emanuele Stoppa <[email protected]>
addressed the ones you mentioned, thanks for the suggestions. |
arendjr
left a comment
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.
Nice work!
Regarding "Operands in bitwise operations (e.g., a & 1, a | 2)", I personally think these shouldn't be an exception. 1 and 2 are already exceptions on their own, and more complex numbers are best assigned to a _MASK or _BITS constant IMO. Otherwise, your code is still not giving any explanation as to why these specific bits are relevant.
Co-authored-by: Arend van Beelen jr. <[email protected]>
Co-authored-by: Arend van Beelen jr. <[email protected]>
RE: 1 and 2 are already exceptions on their own - you are right about 1 and 2 being non magical :-), let me update with other examples. |
|
I can now merge if it goes green right? @arendjr |
arendjr
left a comment
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.
Yep, go for it!
Summary
Added noMagicNumbers rule.
The rule detects and reports the use of "magic numbers" — numeric literals that are used directly in code without being assigned to a named constant.
The no magic numbers rule ignores:
JSON.stringifyandparseInt(e.g.,JSON.stringify(22),parseInt("123", 25))a & 7,a | 7)<div>{1}</div>){ tax: 0.25 })Example
closes #4333