Rule Proposal: object-curly-newline
See original GitHub issueFrom requirePaddingNewLinesInObjects and disallowPaddingNewLinesInObjects.
This will require/disallow line breaks after open object curlies and before close object curlies.
Options
{
"object-curly-newline": [
"error",
"always" or "never" or {"multiline": <boolean>, "minItems": <integer>}
]
}
"always"
- Requires line breaks always."never"
- Disallows line breaks always.- An object - Requires line breaks if any of properties is satisfied. Otherwise, disallows line breaks.
multiline
(default isfalse
) - Requires line breaks if the content is multiline. If this isfalse
, this condition is disabled.minItems
(default is0
) - Requires line breaks if the number of properties is more than the given integer. If this is0
, this condition is disabled.
Examples
/*eslint object-curly-newline: ["error", "always"]*/
// ✔ GOOD
let a = {
};
let b = {
foo: 1
};
let c = {
foo: 1, bar: 2
};
let d = {
foo: 1,
bar: 2
};
let e = {
foo: function() {
dosomething();
}
};
// ✘ BAD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
bar: 2};
let e = {foo() {
dosomething();
}};
/*eslint object-curly-newline: ["error", "never"]*/
// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
bar: 2};
let e = {foo: function() {
dosomething();
}};
// ✘ BAD
let a = {
};
let b = {
foo: 1
};
let c = {
foo: 1, bar: 2
};
let d = {
foo: 1,
bar: 2
};
let e = {
foo: function() {
dosomething();
}
};
/*eslint object-curly-newline: ["error", {"multiline": true}]*/
// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {foo: 1, bar: 2};
let d = {
foo: 1,
bar: 2
};
let e = {
foo: function() {
dosomething();
}
};
// ✘ BAD
let a = {
};
let b = {
foo: 1
};
let c = {
foo: 1, bar: 2
};
let d = {foo: 1,
bar: 2};
let e = {foo: function() {
dosomething();
}};
/*eslint object-curly-newline: ["error", {"minItems": 2}]*/
// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {
foo: 1, bar: 2
};
let d = {
foo: 1,
bar: 2
};
let e = {foo: function() {
dosomething();
}};
// ✘ BAD
let a = {
};
let b = {
foo: 1
};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
bar: 2};
let e = {
foo: function() {
dosomething();
}
};
/*eslint object-curly-newline: ["error", {"multiline": true "minItems": 2}]*/
// ✔ GOOD
let a = {};
let b = {foo: 1};
let c = {
foo: 1, bar: 2
};
let d = {
foo: 1,
bar: 2
};
let e = {
foo: function() {
dosomething();
}
};
// ✘ BAD
let a = {
};
let b = {
foo: 1
};
let c = {foo: 1, bar: 2};
let d = {foo: 1,
bar: 2};
let e = {foo: function() {
dosomething();
}};
Related Rules
brace style | space style | line break style | |
---|---|---|---|
block | brace-style | block-spacing | max-statements-per-line |
object | #6072 object-curly-newline | object-curly-spacing | object-property-newline |
array | #6073 array-bracket-newline | array-bracket-spacing | #6075 array-element-newline |
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (11 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 >[Meta] Use Prettier for formatting JavaScript in Thunderbird
Current eslint rule: // Enforce consistent line breaks inside braces "object-curly-newline": [2, { multiline: true }],. Proposed Prettier-friendly change:
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)
Read more >Eslint rule to put a new line inside import - Stack Overflow
I was looking for such a rule for both import and export declaration. ... Add the object-curly-newline rule to your .eslintrc.json , where ......
Read more >vue/object-curly-newline - eslint-plugin-vue
This rule is the same rule as core object-curly-newline rule but it applies to the expressions in <template> .
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
I updated this proposal. If there are not objection opinions, I want to implement this.
Yes, I was answering the comment https://github.com/eslint/eslint/issues/6072#issuecomment-219219579 actually, referring to the above issue.