`object-curly-newline`: new option request
See original GitHub issueI’m on eslint v2.13.1.
The multiline: true
option is excellent: it lets me require that when newlines exist, every property must be on its own line.
Combining it with minProperties
is half useful, however: when it’s set to, say, 3, that means that any objects with 3 or more properties must be split onto multiple lines, which is great! Unfortunately, this also means that objects with less than 3 properties must not be split onto multiple lines.
What I’d like instead is something like { multiline: true, maxPropertiesBeforeForcedNewline: 2 }
which says that if there are > 2
properties, the object must be multiline, but if there are <= 2
, the object may be single or multi, provided that it’s consistent with the multiline: true
option.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:12
- Comments:15 (13 by maintainers)
Top Results From Across the Web
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 >javascript - ESLint - object-curly-newline - Stack Overflow
Is there a way to allow for {} (an empty object) while keeping the rest as is?
Read more >vue/object-curly-newline - eslint-plugin-vue
vue/object-curly-newline #. Enforce consistent line breaks after opening and before closing braces in <template>. The --fix option on ...
Read more >Code style for JS6 destructured object lacks settings in ...
WEB-32601 The auto-formatter doesn't follow ESLint rules when applying the `object-curly-newline` rule. 2. I want to have something like that:.
Read more >A brand new website interface for an even better experience!
Proposal: "object-curly-newline" add configuration for named imports and exports (or create new rule for import/export specifiers) · Javascript Required. Kindly ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thank you for this issue.
Maybe similar to #6369. I think this is reasonable.
What do you think
either
option?"always"
- requires line breaks always."never"
- disallows line breaks.{multiline: true}
(default) - requires line breaks if there are line breaks inside properties or between properties. Otherwise, disallows line breaks.{minProperties: <integer>}
- requires line breaks if the number of properties is more than the given integer. Otherwise, disallows line breaks.{either: true}
- requires line breaks (of both braces) if either brace has a line break.multiline
andminProperties
andeither
can be combined.{multiline: true, minProperties: <integer>, either: true}
- requires line breaks if there are line breaks inside properties or between properties, or if the number of properties is more than the given integer, or if either brace has a line break. Otherwise, disallows line breaks.If
either
option is enabled, this rule never disallows line breaks.What rule do you want to change?
object-curly-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.)? New option:
consistent
. Whentrue
, it requires that either both curly braces, or neither, directly enclose newlines.Please provide some example code that this change will affect:
What does the rule currently do for this code?
What will the rule do after it’s changed?
Perhaps a better alternative is actually fixing
minProperties
to mean “min properties to force multiline”, instead of meaning “number of properties that determines whether it must be multiline or single-line”, but that gets into the require/disallow complexity.