Rule Proposal: array-element-newline
See original GitHub issueFrom validateNewlineAfterArrayElements.
This will require/disallow line breaks after each array element.
Options
{
"array-element-newline": [
"error",
"always" or "never" or {"multiline": <boolean>, "minItems": <integer>}
]
}
"always"
(default) - 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.minColumn
: (default is0
) - requires line breaks if the max column of properties (if line breaks between properties were removed) is more than the given integer. If this is0
, this condition is disabled.minItems
(default is0
) - Requires line breaks if the number of elements is more than the given integer. If this is0
, this condition is disabled.
Examples
/*eslint array-element-newline: ["error", "always"]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1,
2];
let d = [1,
2,
3];
let e = [
function foo() {
dosomething();
},
function bar() {
dosomething();
}
];
// ✘ BAD
let c = [1, 2];
let d = [1, 2, 3];
let e = [
function foo() {
dosomething();
}, function bar() {
dosomething();
}
];
/*eslint array-element-newline: ["error", "never"]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1, 2, 3];
let e = [
function foo() {
dosomething();
}, function bar() {
dosomething();
}
];
// ✘ BAD
let c = [
1,
2
];
let d = [
1,
2,
3
];
let e = [
function foo() {
dosomething();
},
function bar() {
dosomething();
}
];
/*eslint array-element-newline: ["error", {"multiline": true}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1, 2, 3];
let e = [1,
2,
3];
let f = [
function foo() {
dosomething();
},
function bar() {
dosomething();
}
];
// ✘ BAD
let d = [1,
2, 3];
let e = [
function foo() {
dosomething();
}, function bar() {
dosomething();
}
];
/*eslint array-element-newline: ["error", {"minItems": 3}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1,
2,
3];
let e = [
function foo() {
dosomething();
}, function bar() {
dosomething();
}
];
// ✘ BAD
let c = [1,
2];
let d = [1, 2, 3];
let e = [
function foo() {
dosomething();
},
function bar() {
dosomething();
}
];
/*eslint array-element-newline: ["error", {"multiline": true, "minItems": 3}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1,
2,
3];
let e = [
function foo() {
dosomething();
},
function bar() {
dosomething();
}
];
// ✘ BAD
let d = [1, 2, 3];
let e = [
function foo() {
dosomething();
}, function bar() {
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:8
- Comments:11 (11 by maintainers)
Top Results From Across the Web
array-element-newline - ESLint - Pluggable JavaScript Linter
This rule enforces line breaks between array elements. Options. This rule has either a string option: "always" (default) requires line breaks between array...
Read more >Is there eslint rule for array multiline checking? - Stack Overflow
As far as I know there are no eslint rules for that. But there are proposals for array-bracket-newline and array-element-newline .
Read more >Dodekalogue - the Tcler's Wiki!
It indicates an array element if name is in the form “arrayName(index)” where arrayName does not contain any open parenthesis characters, “(”, or...
Read more >Functions (DriveWorks Documentation)
The NewLine function accepts a NewLine Count value, this specifies the number of new line characters to be inserted. Returns a character to...
Read more >Trailing commas - JavaScript - MDN Web Docs
If you want to add a new property, you can add a new line without ... JavaScript has allowed trailing commas in array...
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
Is this still up? I would implement this.
I updated this proposal. If there are not objection opinions, I want to implement this.