Rule Proposal: array-bracket-newline
See original GitHub issueFrom validateNewlineAfterArrayElements.
This will require/disallow line breaks after open array brackets and before close array brackets.
Options
{
"array-bracket-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 is false, this condition is disabled.minItems
(default is0
) - Requires line breaks if the number of elements is more than the given integer. If this is 0, this condition is disabled.
Examples
/*eslint array-bracket-newline: ["error", "always"]*/
// ✔ GOOD
let a = [
];
let b = [
1
];
let c = [
1, 2
];
let d = [
1,
2
];
let e = [
function foo() {
dosomething();
}
];
// ✘ BAD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1,
2];
let e = [function foo() {
dosomething();
}];
/*eslint array-bracket-newline: ["error", "never"]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [1,
2];
let e = [function foo() {
dosomething();
}];
// ✘ BAD
let a = [
];
let b = [
1
];
let c = [
1, 2
];
let d = [
1,
2
];
let e = [
function foo() {
dosomething();
}
];
/*eslint array-bracket-newline: ["error", {"multiline": true}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [1, 2];
let d = [
1,
2
];
let e = [
function foo() {
dosomething();
}
];
// ✘ BAD
let a = [
];
let b = [
1
];
let c = [
1, 2
];
let d = [1,
2];
let e = [function foo() {
dosomething();
}];
/*eslint array-bracket-newline: ["error", {"minItems": 2}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [
1, 2
];
let d = [
1,
2
];
let e = [function foo() {
dosomething();
}];
// ✘ BAD
let a = [
];
let b = [
1
];
let c = [1, 2];
let d = [1,
2];
let e = [function foo() {
dosomething();
}];
/*eslint array-bracket-newline: ["error", {"multiline": true, "minItems": 2}]*/
// ✔ GOOD
let a = [];
let b = [1];
let c = [
1, 2
];
let d = [
1,
2
];
let e = [
function foo() {
dosomething();
}
];
// ✘ BAD
let a = [
];
let b = [
1
];
let c = [1, 2];
let d = [1,
2];
let e = [function foo() {
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:15
- Comments:23 (22 by maintainers)
Top Results From Across the Web
array-bracket-newline - ESLint - Pluggable JavaScript Linter
This rule enforces line breaks after opening and before closing array brackets. Options. This rule has either a string option: "always" requires line...
Read more >Is there eslint rule for array multiline checking? - Stack Overflow
When defining an object or array with multiple lines, brackets must be on a new line. Is there such rule in eslint or...
Read more >Whitespace · Styleguide JavaScript
Use spacing inside of computed property brackets. ESLint: computed-property-spacing. Examples. ⇣ Incorrect code for this rule: winter[snow ]; winter[ ...
Read more >vue/array-bracket-newline - eslint-plugin-vue
This rule is the same rule as core array-bracket-newline rule but it applies to the expressions in <template> .
Read more >Dodekalogue - the Tcler's Wiki!
A Tcl script is a string containing one or more commands. Semicolons and newlines are command separators unless quoted as described below. Close...
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
@mysticatea just noticed you are assigned. are you championing this? otherwise, I can do it
This was fixed by https://github.com/eslint/eslint/pull/8314.