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
[no-magic-numbers] - false error report on array destructuring declaration #12892
Comments
Thanks for reporting!
In my opinion, It makes sense to treat it as a bug because all numbers are named. |
Something like this might be correct: /* eslint no-magic-numbers: ["error", { "enforceConst": false }] */
const [a, b] = [1, 2]; // ok
let [a, b] = [1, 2]; // ok
var [a, b] = [1, 2]; // ok
[a, b] = [1, 2]; // error /* eslint no-magic-numbers: ["error", { "enforceConst": true }] */
const [a, b] = [1, 2]; // ok
let [a, b] = [1, 2]; // error
var [a, b] = [1, 2]; // error
[a, b] = [1, 2]; // error /* eslint no-magic-numbers: ["error", { "detectObjects": false }] */
[obj.a, obj.b] = [1, 2]; // ok /* eslint no-magic-numbers: ["error", { "detectObjects": true }] */
[obj.a, obj.b] = [1, 2]; // error We could find the assignment target for the number, and if it's a If it's an Perhaps we could do this for object patterns as well, maybe even support nested destructuring. There is also proposal #12611 to optionally allow default assignments. |
Is someone working on it? if not, I'll try it. :) |
@yeonjuan Go for it! Edit: Looks like we still need to finalize the design. I think this should be put behind an option (maybe |
Thanks for replying :) yep I agree, It needs to be designed first. 👍 I was thought it should just work as @mdjermanovic mentioned. :) - but has no strong preference both (option or by default) |
I also think there is no need for an option in this case. Maybe there could be another rule to control whether the |
I don't have a strong opinion either, and do support this change 👍. |
I second this. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
hmm.. I think there was enough activity here to not auto-close |
Reopening since this is an accepted issue, we just need to figure out the design. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
Tell us about your environment
Node version: v12.12.0
npm version: v6.9.0
Local ESLint version: v6.8.0 (Currently used)
Global ESLint version: Not found
What parser (default, Babel-ESLint, etc.) are you using?
typescript 3.8
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
I use Webstorm's built-in eslint reporting service
What did you expect to happen?
No errors reported
What actually happened? Please include the actual, raw output from ESLint.
No magic number: 10. (no-magic-numbers)
Are you willing to submit a pull request to fix this bug?
noooo...
The text was updated successfully, but these errors were encountered: