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.

Rule Proposal: array-bracket-newline

See original GitHub issue

From 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 is false) - Requires line breaks if the content is multiline. If this is false, this condition is disabled.
    • minItems (default is 0) - 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:closed
  • Created 7 years ago
  • Reactions:15
  • Comments:23 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
albertocommented, Jan 5, 2017

@mysticatea just noticed you are assigned. are you championing this? otherwise, I can do it

0reactions
not-an-aardvarkcommented, Apr 22, 2017
Read more comments on GitHub >

github_iconTop 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 >

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