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 treats nested function parameters incorrectly #8892

Closed
seriema opened this issue Jul 7, 2017 · 4 comments · Fixed by homezen/eslint-config-homezen#43
Closed

indent treats nested function parameters incorrectly #8892

seriema opened this issue Jul 7, 2017 · 4 comments · Fixed by homezen/eslint-config-homezen#43
Assignees
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

@seriema
Copy link

seriema commented Jul 7, 2017

Tell us about your environment

  • ESLint Version: v4.1.1
  • Node Version: v5.1.0
  • npm Version: 3.3.12

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

Please show your full configuration:

Configuration
/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 1} }]*/

What did you do? Please include the actual source code causing the issue.
I ran ESlint to check for validation issues.

/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 1} }]*/

define([
  "bar",
  "baz",
  "qux"
],

function (
  bar,
  baz,
  qux
) {
  qux();
});

What did you expect to happen?
I expected no validation issues.

What actually happened? Please include the actual, raw output from ESLint.
It gave me validation errors:

  10:1  error  Expected indentation of 4 spaces but found 2  indent
  11:1  error  Expected indentation of 4 spaces but found 2  indent
  12:1  error  Expected indentation of 4 spaces but found 2  indent
  13:1  error  Expected indentation of 2 spaces but found 0  indent

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

If I run --fix it ends up looking like this, which to me is double the function parameter spacing that I want (it has 4 spaces instead of 2) and it adds 2 spaces before ) {.

define([
  "bar",
  "baz",
  "qux"
],

function (
    bar, // These three parameters should have 2 spaces instead of 4
    baz,
    qux
  ) { // This line should have 0 spaces instead of 2
  qux();
});

Note
Running without the define as a simple method works as expected from the documentation examples. I.e. this works as expected (no validation issues):

/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 1} }]*/

function foo(
  bar,
  baz,
  qux
) {
  qux();
}
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Jul 7, 2017
@seriema seriema changed the title indent FunctionDeclaration does not catch indent FunctionDeclaration does not work with modules Jul 7, 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 Jul 7, 2017
@not-an-aardvark not-an-aardvark changed the title indent FunctionDeclaration does not work with modules indent treats nested function parameters incorrectly Jul 7, 2017
@not-an-aardvark
Copy link
Member

Thanks for reporting, I can reproduce this issue.

@not-an-aardvark not-an-aardvark self-assigned this Jul 7, 2017
not-an-aardvark added a commit that referenced this issue Jul 9, 2017
Previously, the `indent` rule would only offset the first token of an element in a list (e.g. an array). However, this was incorrect because the other tokens of the element might not depend on the indentatio nof the first token. For example, in a function expression, the indentation of the parens does not depend on the indentation of the `function` token. This commit updates the `indent` rule to correctly offset all of the tokens in the element.
@seriema
Copy link
Author

seriema commented Jul 11, 2017

@not-an-aardvark I tried 4.2.0 and the issue isn't really fixed. The example I had above now passes, but if I change the body or parameters to anything other than 1 it still validates as if it was set to 1.

So changing from
/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 1, "parameters": 1} }]*/
to
/*eslint indent: ["error", 2, { "FunctionDeclaration": {"body": 2, "parameters": 2} }]*/
or any other values doesn't affect validation.

@not-an-aardvark
Copy link
Member

I think you want the FunctionExpression option, not FunctionDeclaration.

If it still isn't working after that, please open a new issue.

@seriema
Copy link
Author

seriema commented Jul 12, 2017

Oh, I see. Using FunctionExpression worked. You can update my bug description if you want, as it didn't work before 4.2.0 but my bug report said FunctionDeclaration.

@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