prefer-destructuring should not check non-numeric indexes
See original GitHub issueTell us about your environment
- ESLint Version: 4.14.0
- Node Version: 9.3.9
- npm Version: 5.6.0
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
Configuration
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"extends": [
"airbnb-base"
],
"rules": {
"class-methods-use-this": "off",
"import/no-extraneous-dependencies": ["off", {"devDependencies": ["webpack-config/*.js"]}],
"no-prototype-builtins": "off",
"no-param-reassign": [0],
"prefer-default-export": "off"
}
}
What rule do you want to change? prefer-destructuring
Does this change cause the rule to produce more or fewer warnings? Fewer
How will the change be implemented? (New option, new default behavior, etc.)? New default behavior
Please provide some example code that this change will affect:
const INTEGER_WORDS = {
one: 1,
two: 2,
three: 3,
four: 4,
};
let num = 1;
num = INTEGER_WORDS[num];
What does the rule currently do for this code?
Generates a warning for num = INTEGER_WORDS[num];
What will the rule do after it’s changed?
It will ignore array indexes/keys that are not constants. I would argue this should always be the case, as it must be considered bad practice to destructure from a computed index or key.
Issue Analytics
- State:
- Created 6 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
Use array destructuring (prefer-destructuring) error on eslint
Good advice. Sometimes eslint is just in the way. The prefer-destructuring rule basically doesn't fit for any large arrays? Where "large" is ...
Read more >prefer-destructuring - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >Skipping Values In JavaScript Destructuring - Samantha Ming
You can use blanks to skip over unwanted values in JavaScript. Perfect to avoid creating useless variable assignments for values you don't want...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
The destructuring assignment syntax is a JavaScript expression that makes it possible to unpack values from arrays, or properties from ...
Read more >Array Destructuring – How Does Destructuring Work in JS?
Keep in mind that you do not have to use an empty array as the destructuring parameter's default argument. You can use any...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You could do
let { [num]: num } = INTEGER_WORDS
, but I agree that that should be an exception.The fix seems to be quite easy. I haven’t thought through it deeply, but this works:
Change these lines to:
I added the check for
rightNode.computed
. If that’s true, a non-literal expression is being used.