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: destructuring-property-newline

See original GitHub issue

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:

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:closed
  • Created 6 years ago
  • Reactions:67
  • Comments:59 (32 by maintainers)

github_iconTop GitHub Comments

20reactions
shermendevcommented, Jan 24, 2020

Any updates on the issue?

18reactions
pawelkleczekcommented, Oct 10, 2018

Is there any update about this feature?

Read more comments on GitHub >

github_iconTop Results From Across the Web

eslint-plugin-newline-destructuring - npm
Eslint plugin for enforcing newlines in object destructuring assignment past a certain number of properties.. Latest version: 1.1.1, ...
Read more >
ESLint object destructuring new line formats function
The eslint-plugin-putout package has a couple rules for doing this until it's baked it. Share.
Read more >
object-curly-newline - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Eslint-plugin-newline-destructuring - npm.io
Eslint plugin for enforcing newlines in object destructuring assignment past a certain number of properties. Usage. Add newline-destructuring to the plugins ...
Read more >
eslint-plugin-newline-destructuring - npm package | Snyk
Learn more about eslint-plugin-newline-destructuring: package health score, popularity, ... The rule accepts an option object with the following properties:.
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