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.

"object-property-newline" rule: add option to allow shorthand properties on the same line

See original GitHub issue

What rule do you want to change?

object-property-newline

Does this change cause the rule to produce more or fewer warnings?

Fewer

How will the change be implemented? (New option, new default behavior, etc.)?

A new allowAllShorthandPropertiesOnSameLine option:

  • allowAllShorthandPropertiesOnSameLine: true allows all the shorthand properties to be on the same line.
  • allowAllShorthandPropertiesOnSameLine: false (default) disallows shorthand properties to be on the same line.

[Currently the only possible option is allowAllPropertiesOnSameLine]

Please provide some example code that this change will affect:

const object = {
    shortHandProperty1, shortHandProperty2, property3: "value3", property4: "value4"
};

What does the rule currently do for this code?

With ["error"], expects:

const object = {
    shortHandProperty1,
    shortHandProperty2,
    property3: "value3",
    property4: "value4"
};

What will the rule do after it’s changed?

With ["error", {allowAllShorthandPropertiesOnSameLine: true}], also validates:

const object = {
    shortHandProperty1, shortHandProperty2,
    property3: "value3",
    property4: "value4"
};

Are you willing to submit a pull request to implement this change?

Yes

Comment

I haven’t found any style guide that explicitly recommends this, but it seems to be quite a common pattern to me.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kaicataldocommented, May 29, 2019

What happens if there are a lot of shorthand properties? It seems like you would be forced to do something like this (which I imagine could be viewed as undesirable, particular since it could conflict with max-len):

const object = {
    shortHandProperty1, shortHandProperty2, shortHandProperty3, shortHandProperty4, shortHandProperty5, shortHandProperty6, shortHandProperty7, shortHandProperty8,
    property3: "value3",
    property4: "value4"
};
0reactions
eslint-deprecated[bot]commented, Jul 5, 2019

Unfortunately, it looks like there wasn’t enough interest from the team or community to implement this change. While we wish we’d be able to accommodate everyone’s requests, we do need to prioritize. We’ve found that issues failing to reach accepted status after 21 days tend to never be accepted, and as such, we close those issues. This doesn’t mean the idea isn’t interesting or useful, just that it’s not something the team can commit to.

Thanks for contributing to ESLint and we appreciate your understanding.

Read more comments on GitHub >

github_iconTop Results From Across the Web

object-property-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 >
Shorthand properties - CSS: Cascading Style Sheets | MDN
Shorthand properties are CSS properties that let you set the values of multiple other CSS properties simultaneously.
Read more >
Linter rules for single or multiline object literals - Stack Overflow
I try to set up ESLint rules for both linting and autoformatting of object literal. This snippet should cause linter error: let obj...
Read more >
object-property-newline (Rules) - 开发者手册 - Tencent cloud
This rule permits you to restrict the locations of property specifications in object literals. You may prohibit any part of any property ......
Read more >
vue/object-property-newline - eslint-plugin-vue
The --fix option on the command line can automatically fix some of the problems reported by this rule. This rule is the same...
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