New rule: disallow nested es6 destructuring
See original GitHub issueThe rule should warn in these scenarios:
let {a: {b}, c} = obj; // 1
let {a, a: {b}, c} = obj; // 2
let [a, {b}] = arr; // 3
let [[a]] = arr; // 4
The rule should NOT warn in these scenarios:
let {c} = obj; let {b} = obj.a; // refactored 1
let {a, c} = obj; let {b} = a; // refactored 2
let {a, b, c} = obj;
let [a, b, c] = arr;
This rule is stylistic. Destructuring of nested objects can be confusing and is usually better written in several smaller steps.
I think it’s generic enough for core.
I’m thinking also about configuration options to ignore array destructuring (then examples 3 and 4 would be valid).
I don’t think I can implement it anytime near, but if I need it urgently somewhere, I will do 😃
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:8 (7 by maintainers)
Top Results From Across the Web
Using ES6 To Destructure Deeply Nested Objects in ... - ITNEXT
Today, I will show you how to use ES6 to destructure nested objects, my friends, AND what's more, prevent the dreaded undefined error...
Read more >ES6 Object Destructuring Default Values for Nested Parameters
Show activity on this post. I'm using es6 object destructuring to provide default parameters to a function. The code throws Cannot read ...
Read more >10. Destructuring - Exploring JS
Destructuring is a convenient way of extracting multiple values from data stored in (possibly nested) objects and Arrays. It can be used in...
Read more >ESLint: prefer-destructuring - Styleguide JavaScript
Use object destructuring when accessing and using multiple properties of an object. Destructuring avoids the usage of temporary references for those ...
Read more >JavaScript Object Destructuring, Spread Syntax, and the Rest ...
Basic Object Destructuring Example · Variable Declaration Rule · Add a New Variable & Default Value · Add Aliases · Nested Object Destructuring....
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
@ianvs the issue here is whether or not it belongs in core, not necessarily if the rule is useful. Remember, we purposely raised the bar for the core because we already have over 200 rules.
And a reminder for everyone: our job is not to determine if a rule is useful, it’s to determine if it’s so important that ESLint would seem incomplete without it. Our guidelines: http://eslint.org/docs/developer-guide/contributing/new-rules
👍 Personally I’ve spent way too much time trying to decipher nested destructurings, and would love to see a rule like this. Whether it’s in core, or a plugin is up for debate, but I think it would be a great rule regardless.