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
Update: Add no-magic-numbers 'ignoreDefaultValues' option #12611
Update: Add no-magic-numbers 'ignoreDefaultValues' option #12611
Conversation
I'd consider ignoring nullish coalescing assignment through the same option. const port = process.env.PORT ?? 3000; This can be done with the following additional check. parent.type === 'LogicalExpression' && parent.operator === '??' What do you think? |
40a92dc
to
ee1ef95
Compare
I think this makes sense, though I don't know if it makes sense to put it behind the I support this change. We'll need a champion and two more supporters from the team before we can mark this as accepted. |
Should the option allow all default values regardless of the context? For example, the following are also default assignments ( let WEB;
({ WEB = 3000 } = process.env);
const [foo = 89] = bar;
function doSomething(foo = 33) {}
for (const { value = 42 } of values) {} |
I think yes. For me the purpose is to allow numbers where the variable is providing the necessary description. |
Thanks for the clarification! If the proposal gets accepted we should certainly add more examples in the documentation and more tests to specify the intention. Someone might expect that the option applies only to declarations, while it also allows magic numbers in assignments, e.g.,: [foo = 35, bar = 20] = getSomething(); |
Agreed. I'm awaiting maintainer approval to update the PR. |
Hi all! I would still love this option. Is there anything I can do to move this forward? Besides rebase and resolve conflicts 😁 |
@eslint/eslint-team It looks like we need a champion and one more 👍 to accept this. |
I will champion this. @moeriki if you're still up to update this PR, we can move forward. Sorry for the delay. |
This makes a lot of sense. Added my 👍 and marking as accepted! |
ee1ef95
to
d07b0b0
Compare
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.
Code LGTM, but it looks like we're missing tests for array destructuring with default values. e.g.
const [ el = 123] = arr;
7276334
to
4cda76d
Compare
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.
Two minor alterations, then LGTM - thanks for working on this @moeriki!
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.
Other than the two JSDoc comment updates requested by @mdjermanovic, LGTM - thank you!
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.
LGTM, thanks!
@kaicataldo if you're happy with the array destructuring default tests in 7a942b6, then this can be merged! |
@moeriki Do you mind fixing up the merge conflict? Otherwise LGTM. |
…gnore-default-values * upstream/master: (66 commits) Sponsors: Sync README with website Sponsors: Sync README with website Sponsors: Sync README with website Sponsors: Sync README with website Sponsors: Sync README with website Chore: remove leche (fixes eslint#13287) (eslint#13533) Sponsors: Sync README with website Sponsors: Sync README with website 7.6.0 Build: changelog update for 7.6.0 Update: require `meta` for fixable rules in RuleTester (refs eslint#13349) (eslint#13489) Docs: fix broken links in developer guide (eslint#13518) Fix: Do not output `undefined` as line and column when it's unavailable (eslint#13519) Sponsors: Sync README with website Sponsors: Sync README with website Fix: Update the chatroom link to go directly to help channel (eslint#13536) Sponsors: Sync README with website Update: Change no-duplicate-case to comparing tokens (fixes eslint#13485) (eslint#13494) Docs: add ECMAScript 2020 to README (eslint#13510) 7.5.0 ...
Merged master back in. I mistakenly removed my committer email from my GitHub account. I did add it again. The CLA should be fine. |
The most recent review was "Otherwise LGTM" once the merge conflict was resolved, which it has been.
Thanks @moeriki! I'm looking forward to having this in the next release. |
This was briefly discussed in #10751 and #11271. As far as I could tell people thought it was a good idea.
What is the purpose of this pull request?
[X] Changes an existing rule
What rule do you want to change?
no-magic-numbers
Does this change cause the rule to produce more or fewer warnings?
Fewer.
How will the change be implemented?
I added an option called
ignoreDefaultValues
.Please provide some example code that this change will affect:
What does the rule currently do for this code?
Error: No magic number: 3000
Error: No magic number: 2
What will the rule do after it's changed?
∅