New rule: destructuring-property-newline
Problem
Please 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: [code block] 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: [code block] Examples of correct code for this rule: [code block] 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: [code block] Why should this rule be included in ESLint (inste
Error Output
error suggesting a multiline destructuring like so:
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: New rule: destructuring-property-newline
@eslint/eslint-team: This should be a pretty simple stylistic rule for us to add, and it covers a core functionality gap (no way to enforce object destructuring style). The proposal is to create a rule `destructuring-property-newline` which would be very similar to `object-property-newline`, but cover object destructuring. I don't think it's a good idea to augment `object-property-newline` to ha
Trust Score
6 verifications
- 1
@eslint/eslint-team: This should be a pretty simple stylistic rule for us to add
@eslint/eslint-team: This should be a pretty simple stylistic rule for us to add, and it covers a core functionality gap (no way to enforce object destructuring style).
- 2
The proposal is to create a rule `destructuring-property-newline` which would be
The proposal is to create a rule `destructuring-property-newline` which would be very similar to `object-property-newline`, but cover object destructuring.
- 3
I don't think it's a good idea to augment `object-property-newline` to handle de
I don't think it's a good idea to augment `object-property-newline` to handle destructuring because object properties and destructuring properties are syntactically and semantically different.
- 4
Can we get some :+1:s for the issue?
Can we get some :+1:s for the issue?
Validation
Resolved in eslint/eslint GitHub issue #9259. Community reactions: 14 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep