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

newline-after-var rule is broken with babel-eslint >= 9 #11839

Closed
brokenmass opened this issue Jun 14, 2019 · 2 comments
Closed

newline-after-var rule is broken with babel-eslint >= 9 #11839

brokenmass opened this issue Jun 14, 2019 · 2 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint

Comments

@brokenmass
Copy link

Tell us about your environment

  • ESLint Version: 5.16.0
  • Node Version: 10
  • npm Version: 6.10

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

Please show your full configuration:

Configuration
module.exports = {
  env: {
    browser: true,
    es6: true,
    node: true
  },
  parser: 'babel-eslint',
  parserOptions: {
    ecmaFeatures: {
      globalReturn: false,
      impliedStrict: true,
      jsx: true
    },
    ecmaVersion: 2017,
    sourceType: 'module'
  },
  plugins: [
    'babel'
  ],
  "rules": {
    "newline-after-var": [
      "error",
      "always"
    ]
  }
}

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 const1 = 1;
let variable1 = 1;
let variable2 = 1;
let variable3 = 1;
eslint --ignore-path .gitignore '**/*.js'

What did you expect to happen?
expected eslint to not return any error

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

eslint-newline-after-var-bug/index.js
  1:1  error  Expected blank line after variable declarations  newline-after-var
  2:1  error  Expected blank line after variable declarations  newline-after-var
  3:1  error  Expected blank line after variable declarations  newline-after-var

Explanation
Since version 9.0.0, babel-eslint broke the eslint rule newline-after-var. the reason is that since that version they have been using @babel/parser@^7 and that changed how the code AST is generated. In the specific let token does not have Keyword type anymore but instead has type Identifier (this is probably because of this so this problem is also loosely correlated to #11830)

This change affect the newline-after-var rule as it use the following check to group together chunks of variable declaration (link to actual code):

if (nextToken.type === "Keyword" && isVar(nextToken.value)) {
  return;
}

while the second part of the if is still valid the first now fails for let variables (this bug does not affects const or var)

Related babel-eslint issue
babel/babel-eslint#771

Are you willing to submit a pull request to fix this bug?
yes if we can agree on a solution and where to implement it (eslint@newline-after-var rule or babel-eslint@babylon-to-espree code)

@brokenmass brokenmass added bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jun 14, 2019
@g-plane
Copy link
Member

g-plane commented Jun 14, 2019

Hey @brokenmass , thanks for the issue.

This rule has been deprecated.

@g-plane g-plane added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly triage An ESLint team member will look at this issue soon labels Jun 14, 2019
@brokenmass
Copy link
Author

brokenmass commented Jun 14, 2019

@g-plane thanks for the quick response. I totally missed the fact that the rule had been deprecated.

@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Dec 12, 2019
@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 Dec 12, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint
Projects
None yet
Development

No branches or pull requests

2 participants