Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: array-bracket-newline consistent error with comments (fixes #12416) #12441

Merged
merged 1 commit into from Oct 20, 2019

Conversation

mdjermanovic
Copy link
Member

What is the purpose of this pull request? (put an "X" next to item)

[X] Bug fix #12416

Tell us about your environment

  • ESLint Version: 6.5.1
  • Node Version: 10.16.0
  • npm Version: 6.9.0

What parser (default, Babel-ESLint, etc.) are you using?

default

Please show your full configuration:

Configuration
module.exports = {
  parserOptions: {
    ecmaVersion: 2015,
  }
};

What did you do? Please include the actual source code causing the issue.

Online Demo Link

/*eslint array-bracket-newline: ["error", "consistent"]*/

const foo = [ // comment
  1,
  2
];

What did you expect to happen?

No errors.

What actually happened? Please include the actual, raw output from ESLint.

  3:13  error  There should be no linebreak after '['   array-bracket-newline
  6:1   error  There should be no linebreak before ']'  array-bracket-newline

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 that always 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.

@mdjermanovic mdjermanovic added bug ESLint is working incorrectly rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Oct 15, 2019
Copy link
Member

@g-plane g-plane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@platinumazure platinumazure merged commit 51fbbd7 into master Oct 20, 2019
@platinumazure platinumazure deleted the issue12416 branch October 20, 2019 19:10
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Apr 19, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Apr 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion bug ESLint is working incorrectly rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[array-bracket-newline] doesn't handle inline comments properly
4 participants