Fix: array-bracket-newline consistent error with comments (fixes #12416) #12441
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
What is the purpose of this pull request? (put an "X" next to item)
[X] Bug fix #12416
Tell us about your environment
What parser (default, Babel-ESLint, etc.) are you using?
default
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue.
Online Demo Link
What did you expect to happen?
No errors.
What actually happened? Please include the actual, raw output from ESLint.
What changes did you make? (Give an overview)
Check for the linebreak between
[
and the first non-comment token inside, instead of between[
and the first token including comments.Is there anything you'd like reviewers to focus on?
This was certainly unexpected behavior of the
consistent
option, given thatalways
option doesn't report errors on the same code (Demo Link).All tests added in
valid
were invalid before this change.Two added
invalid
tests were already invalid, but in a different way. The rule was reporting unexpected linebreaks after the opening brackets (Demo Link). After the change, the rule will report missing linebreaks before the closing brackets.I think that this change in general cannot generate more warnings - arrays/patterns that were valid will stay valid. The only difference, apart from fixing the original example, is in what the rule reports in cases such as those two invalid.