New rule: destructuring-property-newline
See original GitHub issuePlease describe what the rule should do: It would function almost exactly like object-property-newline except on destructured variables. Much of the below is an adaptation of that rule.
It 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?
What category of rule is this? (place an “X” next to just one item)
[x] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Examples of incorrect code for this rule:
/*eslint object-property-newline: "error"*/
const { foo, bar, baz, abc, xyz, foobar, foobaz, bazfoo, barfoo, abcxyz, xyzabc, foobarbaz, bazbarfoo } = foobarbazabcxyz;
Examples of correct code for this rule:
const {
foo,
bar,
baz,
abc,
xyz,
foobar,
foobaz,
bazfoo,
barfoo,
abcxyz,
xyzabc,
foobarbaz,
bazbarfoo
} = foobarbazabcxyz;
Options
This rule has an object option:
"allowMultiplePropertiesPerLine"
:true
allows all keys and values to be on the same line
allowMultiplePropertiesPerLine
Examples of additional correct code for this rule with the { "allowMultiplePropertiesPerLine": true }
option:
/*eslint object-property-newline: ["error", { "allowMultiplePropertiesPerLine": true }]*/
var { foo: "foo", bar: "bar", baz: "baz" } = obj
var {
foo: "foo", bar: "bar", baz: "baz"
} = obj2
Why should this rule be included in ESLint (instead of a plugin)?
For the reasons we have the rule (object-property-newline
)
[https://github.com/eslint/eslint/pull/5933], which draws from (JSCS requireObjectKeysOnNewLine)[http://jscs.info/rule/requireObjectKeysOnNewLine.html]
To quote the reasons for object-property-newline
:
While formatting preferences are very personal, a number of style guides require that object properties be placed on separate lines for better readability.
Another argument in favor of this style is that it improves the readability of diffs when a property is changed:
Issue Analytics
- State:
- Created 6 years ago
- Reactions:67
- Comments:59 (32 by maintainers)
Top GitHub Comments
Any updates on the issue?
Is there any update about this feature?