question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

New rule: disallow nested es6 destructuring

See original GitHub issue

The 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:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
nzakascommented, Jul 22, 2016

@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

1reaction
IanVScommented, Jul 22, 2016

👍 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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found