New rule: Multiline destructuring for many variables
See original GitHub issueWhen 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:
- Created 8 years ago
- Comments:13 (8 by maintainers)
Top GitHub Comments
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.
@frodosamoa if you do make this rule as a plugin, please post back here and let us know. I, for one, would use it.