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

indent handles variable declarations incorrectly when the first declarator is on a new line #8785

Closed
benoitvidis opened this issue Jun 23, 2017 · 1 comment · Fixed by homezen/eslint-config-homezen#43
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 indent Relates to the `indent` rule rule Relates to ESLint's core rules

Comments

@benoitvidis
Copy link

Tell us about your environment

  • ESLint Version: 4.0.0
  • Node Version: 6.9.2
  • npm Version: 5.0.3

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

Please show your full configuration:

"rules": {
  "indent": [2, 2, {"SwitchCase": 1}],
}

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

const 
  o = {
    foo: 'bar'
  },
  p = true;

console.log(o, p);

What did you expect to happen?

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

test.js
  3:1  error  Expected indentation of 6 spaces but found 4  indent
  4:1  error  Expected indentation of 4 spaces but found 2  indent

✖ 2 problems (2 errors, 0 warnings)
  2 errors, 0 warnings potentially fixable with the `--fix` option

Works fine with eslint 3.x and if only one variable is declared at a time.

@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jun 23, 2017
@not-an-aardvark not-an-aardvark added accepted There is consensus among the team that this change meets the criteria for inclusion bug ESLint is working incorrectly indent Relates to the `indent` rule rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Jun 23, 2017
@not-an-aardvark not-an-aardvark changed the title multi-line object declaration breaks indent.ObjectExpression indent handles variable declarations incorrectly when the first declarator is on a new line Jun 23, 2017
@not-an-aardvark
Copy link
Member

Thanks for reporting, I can reproduce this issue.

not-an-aardvark added a commit that referenced this issue Jun 25, 2017
This fixes the `indent` rule's VariableDeclarator logic to correctly handle the case where a declaration has more than one declarator, but neither is on the same line as the start of the declaration.

This also updates the variable declarator listener to be slightly more similar to the logic for other nodes. Previously, variable declarators were treated as a special case and handling them involved overwriting some of the previously-declared offsets while exiting the node. Unfortunately, declarators are still a special case, but their logic isn't quite as different now -- the correct behavior is applied when entering the node, like it is for other node types.
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Feb 6, 2018
@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 Feb 6, 2018
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 indent Relates to the `indent` rule rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants