Request option for array-bracket-newline to only enforce adding line breaks, not removing of line breaks
See original GitHub issueWhat 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:
-
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.
-
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:
- Created 4 years ago
- Comments:23 (10 by maintainers)
Top GitHub Comments
This is a ‘multiline’ array:
This isn’t a ‘multiline’ array:
I hope this helps to clarify the ‘multiline’ logic.
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.