[array-bracket-newline
] Add option consistent
to the object configuration
#13582
Labels
archived due to age
This issue has been archived; please open a new issue for any further discussion
enhancement
This change enhances an existing feature of ESLint
rule
Relates to ESLint's core rules
What rule do you want to change?
array-bracket-newline
Does this change cause the rule to produce more or fewer warnings?
By default: no change.
When option enabled: fewer.
How will the change be implemented? (New option, new default behavior, etc.)?
New option
Please provide some example code that this change will affect:
What does the rule currently do for this code?
It reports two errors for the
test1
array:What will the rule do after it's changed?
It won't report any errors, meaning that it will allow for an array to either be multiline with new lines between elements, or force consistent line breaks for opening and closing brackets.
Important note: this proposal is NOT about changing the behaviour of the already existing
consistent
(string) variant of this rule, but about a new property to the object-like configuration. Please read my explanation in its entirely before jumping to conclusions about possible redundancy.The reasoning behind this is as follows:
multiline: true
option forces to either write all elements of an array in one line (one after another), or split them into multiple lines. This behaviour is already implemented and well-documented (... requires line breaks if there are line breaks inside elements or between elements.
). This however, does not allow one-line element enumerations (whether it's just one or multiple elements) to be started from a new line (when looking at the bracket opening -> first element), because now the rule does not consider this situation to require line breaks, and in turn forbids line breaks entirely.[ 'error', 'consistent' ]
is not able to achieve the same effect, because even though it allows for one-liners to start from a new line, it only checks the brackets, disregarding whether there are any line breaks between elements.multiline
checks both brackets and elements line breaks. To better visualise this, using only the string-like optionconsistent
treats this code as valid:consistent: true
option would additionally force to consistently open & close brackets in the same line as all the elements, or in new lines, regardless of whether the elements are actually split or not (as a whole). Therefore, it would not affect themultiline
option, but rather provide additional constraint with accordance to how the object-shaped configuration for this rule is supposed to work (... Requires line breaks if any of properties is satisfied.
).consistent
option to the object-shaped configuration would additionally bring this rule closer to howobject-curly-newline
works (which already does provide what I propose here).To prevent breaking changes, this option would have to be set to
false
by default. For consistency withobject-curly-newline
, it could be put into consideration to enable it by default, but that's a matter for another PR.There was a discussion similar to this one in the past (#12736), however I believe that either the author did not describe their intent correctly, or the ESLint's contributors were too absorbed with the proposed "multiline option extension", so hopefully my explanation will bring a new perspective to this old proposal.
Are you willing to submit a pull request to implement this change?
Yes, I believe this can be achieved in a similar fashion to how
object-curly-newline
does this and can do it in my spare time.The text was updated successfully, but these errors were encountered: