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: Multiline destructuring for many variables

See original GitHub issue

When does this rule warn? Please describe and show example code:

So, let’s say I want to destructure lots of variables at once like so:

const { foo, bar, baz, abc, xyz, foobar, foobaz, bazfoo, barfoo, abcxyz, xyzabc, foobarbaz, bazbarfoo } = foobarbazabcxyz;

the line length can get pretty long. Readability decreases. I think it could be useful if there was a rule that detected the amount of characters in a line or the amount of variables being destructured. If that number happens to be too large (not sure what the right number here is), throw a warning/error suggesting a multiline destructuring like so:

const {
  foo,
  bar,
  baz,
  abc,
  xyz,
  foobar,
  foobaz,
  bazfoo,
  barfoo,
  abcxyz,
  xyzabc,
  foobarbaz,
  bazbarfoo
} = foobarbazabcxyz;

Is this rule preventing an error or is it stylistic?

This rule is stylistic.

Why is this rule a candidate for inclusion instead of creating a custom rule?

Readability is important!

Are you willing to create the rule yourself?

Sure, why not!

Opening this up for discussion!

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
ilyavolodincommented, Oct 2, 2015

I think this can be generalized more. Basically we could create a rule that would capture any list of comma-separated items (object declarations, arrays, destruction, function invocations, function declarations, etc.) and enforce a limit as to how many items can be written on the same line. If threshold is passed, every item has to be on the separate line.

1reaction
IanVScommented, Mar 30, 2016

@frodosamoa if you do make this rule as a plugin, please post back here and let us know. I, for one, would use it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLINT How do I enable multiline for object patterns ...
This is what happens when I separate the identifiers by lines within destructured objects. GIF showing ESLINT not allowing multiple-lines ...
Read more >
ES6 Destructuring and Variable Renaming Explained!
Destructuring objects and arrays is probably the most used feature in ES6 and for good reason. This simple technique is amazing for writing ......
Read more >
ESLint: prefer-destructuring - Styleguide JavaScript
Use object destructuring for multiple return values instead of array destructuring. New properties can not be added over time or the order of...
Read more >
Destructuring assignment - JavaScript - MDN Web Docs
As for object assignment, the destructuring syntax allows for the new variable to have the same name or a different name than the...
Read more >
ES2015 Destructuring & More - Medium
Everything that applies to destructuring objects applies here as well — so you can nest the named parameters, bind to different variable names, ......
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