[array-bracket-newline] doesn't handle inline comments properly
See original GitHub issueTell us about your environment
- ESLint Version: 6.5.1
- Node Version: 10.15.0
- npm Version: 6.4.1
What parser (default, Babel-ESLint, etc.) are you using?
@typescript-eslint/parser
Please show your full configuration:
Here it is, just uncomment the “array-bracket-newline” rule.
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
const asd = [ // comment
123,
123
];
npx eslint src --ext '.ts, .tsx'
What did you expect to happen?
No error detected.
What actually happened? Please include the actual, raw output from ESLint.
Adding an inline comment like that trips this rule, the array is actually consistently written as far as I’m concerned but the rule is kind of considering the inline comment as an item of the array.
Are you willing to submit a pull request to fix this bug?
I’m not too familiar with the AST, but with some pointers perhaps I can help.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top GitHub Comments
I’m working on this.
This is related to the
consistent
option only.Online Demo Link
This looks like a bug to me. The above example is auto-fixed to:
where the rule still reports the first error. This could be manually fixed to not report the error like this:
or like this:
I don’t think that the rule intends to enforce neither of those fixes, given how the other options work. In particular,
always
doesn’t report an error for the same example:It seems inconsistent that
always
sees the same example as two correct linebreaks after/before the brackets, whileconsistent
doesn’t.The code for the
consistent
option checks if there is a linebreak between[
and the first token inside (including comments). Based on the result, it requires/disallows linebreaks between brackets and other tokens (not including comments).Couldn’t find anything specific about this in #9136 and #9206 where the option is implemented and there are no test cases with the
consistent
option and some comments.I think that this should be accepted as a bug.
Bug fix would be to check for a linebreak between the
[
and the first non-comment token. I’m not 100% sure but it seems that this fix even can’t produce more errors in other cases.