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-element-newline

See original GitHub issue

From 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 is false) - Requires line breaks if the content is multiline. If this is false, this condition is disabled.
    • minColumn: (default is 0) - requires line breaks if the max column of properties (if line breaks between properties were removed) is more than the given integer. If this is 0, 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-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:closed
  • Created 7 years ago
  • Reactions:8
  • Comments:11 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
JPeer264commented, Mar 23, 2017

Is this still up? I would implement this.

1reaction
mysticateacommented, May 14, 2016

I updated this proposal. If there are not objection opinions, I want to implement this.

Read more comments on GitHub >

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

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