prefer-destructuring proposes object destructuring for array
See original GitHub issue- ESLint Version: 3.13.0
- Node Version: 7.4.0
- npm Version: 4.0.5
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
'prefer-destructuring': [2, { array: true, object: true }, { enforceForRenamedProperties: true }]
What did you do? Please include the actual source code causing the issue.
/******************************************************************************/
'use strict';
/******************************************************************************/
const arr = ['a', 'b', 'c'];
const last = arr[arr.length - 1];
console.log(last);
What did you expect to happen? No error report.
What actually happened? Please include the actual, raw output from ESLint.
5:7 error Use object destructuring prefer-destructuring
The same with this code (that seems to contradict ‘Examples of correct code for this rule’ in the doc).
/******************************************************************************/
'use strict';
/******************************************************************************/
const arr = ['a', 'b', 'c'];
const lastIndex = arr.length - 1;
const last = arr[lastIndex];
console.log(last);
6:7 error Use object destructuring prefer-destructuring
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
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 >How do I pass eslint's "prefer-destructuring" rule if I'm ...
I wanted to reassign two variables to the two properties specifically in the [0] position of the array. I did: clientX = evt.touchEvents[0] ......
Read more >Destructuring Arrays & Objects: JavaScript ES6 Feature Series ...
For my final installment in this series, I will tackle array and object destructuring: the most concise way to pull out values and ......
Read more >prefer-destructuring - Rules - ESLint - GitHub Pages
Each property accepts an object that accepts two properties, array and object , which can be used to control the destructuring requirement for...
Read more >[Pitch] Destructuring Assignment of Structs and Classes
I'd like to propose adding destructuring assignment for both structs and ... This pitch does not include index-based destructuring of Array ...
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
I believe in the first snippet, the line
can be written as
And in the second snippet
is the same as
I honestly agree that enforcing destructuring with the computed property is confusing and not very easy to read. I would support an option to relax this rule for computed properties. Maybe
enforceForComputedProperties
, to be in line with the current schema?