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.

Bug: `array-element-newline` fails when `multiline` = `true`

See original GitHub issue

Tell us about your environment

  • ESLint Version: 4.3.0
  • Node Version: *
  • npm Version: *

What parser (default, Babel-ESLint, etc.) are you using? I had this happen locally, but I’ve been able to duplicate it using http://eslint.org/demo

Please show your full configuration:

Configuration
{
  rules: {
    "array-element-newline": [ "error", { "multiline": true } ]
  }
}

What did you do? Please include the actual source code causing the issue.

var blah = [
  0,
  1
];

What did you expect to happen? array-element-newline rule should succeed

What actually happened? Please include the actual, raw output from ESLint.

The evaluated to a failure.

Output:

4:5 - There should be no linebreak here. (array-element-newline)



This can be easily reproduced if you go to http://eslint.org/demo, uncheck all rules, and insert the following text into the input box:

/*eslint array-element-newline: ["error", { "multiline": true }]*/

var blah = [
  0,
  1
];

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
bsaracommented, Jul 21, 2017

Wow, I didn’t notice that at all. Sorry to bug you guys with this.

Perhaps multiline should be renamed to multiline-element to avoid confusion. It actually took reading the doc a few times before I really caught the part that says “if there are line breaks inside elements”.

Also, a multi-line option that enforces when any element is on a newline would be useful.

0reactions
richardpringlecommented, Feb 28, 2018

So… I might just be going crazy here but I swear you used to be able to enforce a rule where elements cannot overlap.

The most common case (maybe the only case) that I’m looking to solve is as follows:

const arr = [{
    hello: 'world'
  }, {
    foo: 'bar'
}]

What I would like to see is the ability to enforce that all array elements either share a single line or that no elements share lines. An oversimplification of this is that every line in a multiline array should end with a comma (except the last, depending on comma dangle).

Read more comments on GitHub >

github_iconTop Results From Across the Web

array-element-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 >
toml/array-element-newline | eslint-plugin-toml
This rule enforces line breaks between array elements. 1. 2. 3.
Read more >
How do I handle newlines in JSON? - Stack Overflow
I used this function to strip newline or other characters in data to parse JSON data: function normalize_str($str) { $invalid = array( ...
Read more >
Template literals (Template strings) - JavaScript | MDN
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded ...
Read more >
vue/max-attributes-per-line
An attribute is considered to be in a new line when there is a line break ... are acceptable per line in multi-line...
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