prefer-destructuring and reassignment of variables
See original GitHub issueFor example, we have code like:
let error;
if (data.detail) {
if (data.detail.error) {
error = data.detail.error;
} else {
doSomething();
error = data.detail;
}
} else {
error = data.error;
}
doSomethingWith(error);
prefer-destructuring
rule reports 2 issues for this code. I have no ideas how to beautifully refactor this code for following this rule, only renaming a variable and it does not look like a good solution.
So I propose to add an option for reporting about it only for variable declarations, not for assignment expressions.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:25
- Comments:13 (9 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 to fix Eslint error "prefer-destructuring"? - Stack Overflow
this syntax create an array from variables: var x = [y, z] . destructuring assignment uses similar syntax, but on the left-hand side...
Read more >prefer-destructuring - Rules - ESLint - GitHub Pages
With JavaScript ES6, a new syntax was added for creating variables from an array index or object property, called destructuring. This rule enforces...
Read more >eslint-browser/prefer-destructuring.md at master - GitHub
A fully pluggable tool for identifying and reporting on patterns in JavaScript. - eslint-browser/prefer-destructuring.md at master ...
Read more >Destructuring assignment - JavaScript - MDN Web Docs
In an array destructuring from an array of length N specified on the right-hand side of the assignment, if the number of variables...
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
Maybe the documentation for this new rule could use some more examples, but in this case, all it really takes to apply destructuring are parentheses:
Seems like a good idea to me. 👍
Maybe we could have two separate options (one for variable declarations and one for assignment expressions):