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.

Request option for array-bracket-newline to only enforce adding line breaks, not removing of line breaks

See original GitHub issue

What rule do you want to change?

array-bracket-newline

Does this change cause the rule to produce more or fewer warnings?

Fewer

How will the change be implemented? (New option, new default behavior, etc.)?

~Same defaults, but new default behavior~

New option for “multiline”: true that only enforces adding of line breaks, not removing of line breaks.

Please provide some example code that this change will affect:

indexes: [ /** Line 34 */
   { name: `serialNumber`, type: `BTREE`, columns: [ `serialNumber` ] }, 
 ]

What does the rule currently do for this code?

34:12 error There should be no linebreak after ‘[’ array-bracket-newline 36:3 error There should be no linebreak before ‘]’ array-bracket-newline

What will the rule do after it’s changed?

Not error just because there is a single line in array with line breaks after/before the [ and ].

Are you willing to submit a pull request to implement this change?

Sure

Summary

Note: The below comments are based on original issue, which has since been updated to reflect new option request instead of changes to default behavior.

A couple quick points:

  1. The rule as-is assumes that one element is small, but multiple elements are large. This is not necessarily true, one element may be an object which is large and looks way better on a line by itself. Meanwhile, 10 elements could be small enough to easily fit on one line (e.g. small integers), yet the rule has no problem with them being on separate lines.

  2. If you read the configuration options for the rule, the “multiline”: true option, with no other options set, SHOULD behave according to this proposed change based on the way it’s described:

“multiline”: true (default) requires line breaks if there are line breaks inside elements or between elements. If this is false, this condition is disabled.

Note: it says this condition is disabled if false, NOT that it errors when false. See what I mean? The rule seems meant to require new lines when there are line breaks inside elements or between elements, it’s NOT saying new lines are not allowed for single elements. Nor does it anywhere else, as the minItems rule is supposed to be ignored by default.

Thanks for your attention and for everything you guys do!

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:23 (10 by maintainers)

github_iconTop GitHub Comments

2reactions
mdjermanoviccommented, Jan 4, 2020

This is a ‘multiline’ array:

[
  1,
  2
]

This isn’t a ‘multiline’ array:

[
  1, 2
]

I hope this helps to clarify the ‘multiline’ logic.

1reaction
om-mani-padme-humcommented, Jan 11, 2020

ESLint is also fully pluggable, so you can always also just create your own rules (without having to run your own forked version of ESLint). More info can be found here.

I’m not using it, I instead just put in /** eslint-disable-line */ comments in my files. I just set it up so that it was ready for a pull-request if the consensus is reached to approve the addition of this option. Thanks for the tip though, I will likely use that functionality in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[`array-bracket-newline`] Add option `consistent` to the object ...
The multiline: true option forces to either write all elements of an array in one line (one after another), or split them into...
Read more >
Clang-format line breaks - c++ - Stack Overflow
So, having messed around in the clang format code and made some patches, here's my two cents: Clang format is based on,.
Read more >
Handle line breaks (newlines) in Python - nkmk note
This article describes how to handle strings including line breaks (line feeds, new lines) in Python. Create a string containing line breaks.
Read more >
How to Remove Line Breaks in Excel (3 Easy Ways)
Learn how to quickly remove line breaks in Excel with a few simple techniques (using Find and Replace, a formula method, and VBA)...
Read more >
GitLab Flavored Markdown (GLFM)
These lines are only separated by single newlines, so they do not break and just follow the previous lines in the same paragraph....
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