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.VariableDeclarators insufficient for different scenarios #5492

Closed
ffxsam opened this issue Mar 6, 2016 · 8 comments
Closed

indent.VariableDeclarators insufficient for different scenarios #5492

ffxsam opened this issue Mar 6, 2016 · 8 comments
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

Comments

@ffxsam
Copy link

ffxsam commented Mar 6, 2016

I ran into a problem just now, with this code:

    const a = 'asdf',
          b = 'asdfjkhg';
    const arrayOfObjects = [
      {
        name: 'Bob',
        age: 32,
      },
      {
        name: 'Mary',
        age: 32,
      },
    ];

No matter how I set VariableDeclarators, I can't win. :) Either it complains about the alignment of variables a and b, or if I adjust for that, it complains about the curly braces.

IMO, and according to how I interpret the documentation, VariableDeclarators should only be concerned with indentation of variable names, not indentation of other syntax such as brackets and braces. In other words, the code above should be totally valid given this setting:

    "indent": [2, 2, {
      "SwitchCase": 1,
      "VariableDeclarator": {"let": 2, "const": 3}
    }],
@eslintbot eslintbot added the triage An ESLint team member will look at this issue soon label Mar 6, 2016
@gyandeeps gyandeeps added the needs info Not enough information has been provided to triage this issue label Mar 7, 2016
@eslintbot
Copy link

Hi @ffxsam, thanks for the issue. It looks like there's not enough information for us to know how to help you. If you're reporting a bug, please be sure to include:

  1. The version of ESLint you are using (run eslint -v)
  2. What you did (the source code and ESLint configuration)
  3. The actual ESLint output complete with numbers
  4. What you expected to happen instead

Requesting a new rule? Please see Proposing a New Rule for instructions.

If it's something else, please just provide as much additional information as possible. Thanks!

@ffxsam
Copy link
Author

ffxsam commented Mar 7, 2016

Version 2.2.0.

@gyandeeps
Copy link
Member

Can you also provide

The actual ESLint output complete with number

@ffxsam
Copy link
Author

ffxsam commented Mar 7, 2016

Sure. Here's the code. Line 25 is the first line:

    const varA = 'test',
          varB = 'test2';
    const others = [
      {
        thing: 'sky',
        color: 'blue',
      },
      {
        thing: 'dirt',
        color: 'brown',
      },
    ];

My .eslintrc is set to:

    "indent": [2, 2, {
      "SwitchCase": 1,
      "VariableDeclarator": {"let": 2, "const": 3}
    }],

I get the following errors:

  28:7  error  Expected indentation of 10 space characters but found 6  indent
  29:9  error  Expected indentation of 12 space characters but found 8  indent
  30:9  error  Expected indentation of 12 space characters but found 8  indent
  31:7  error  Expected indentation of 10 space characters but found 6  indent
  32:7  error  Expected indentation of 10 space characters but found 6  indent
  33:9  error  Expected indentation of 12 space characters but found 8  indent
  34:9  error  Expected indentation of 12 space characters but found 8  indent
  35:7  error  Expected indentation of 10 space characters but found 6  indent

If I modify the indent settings by commenting out VariableDeclarator:

    "indent": [2, 2, {
      "SwitchCase": 1//,
      //"VariableDeclarator": {"let": 2, "const": 3}
    }],

Then I get this:

  26:11  error  Expected indentation of 6 space characters but found 10  indent

There needs to be separate considerations for indenting/aligning variable names, and indenting braces/brackets.

@dgreensp
Copy link
Contributor

dgreensp commented Mar 7, 2016

I've been grappling with this problem over the past week, including with ESLint 2.3.0. It "fixes" this code with excessive indentation:

     it('displays correct collapsed icon', function() {
       const instance = renderComponent(
-        {
-          collapsedIconName: 'collapsedIconName',
-          expandedIconName: 'expandedIconName'
-        },
+            {
+              collapsedIconName: 'collapsedIconName',
+              expandedIconName: 'expandedIconName'
+            },
         'FOOBAR');

@ffxsam
Copy link
Author

ffxsam commented Mar 7, 2016

Yep. Exactly why I think that VariableDeclarator needs to be modified so that it only cares about indentation of variable names:

const someLongVar = 3,
      anotherVar = 8;

But not braces, brackets, parens, and other non-alpha syntax:

  const someVar = [
    () => { stuff(); },
    () => { moreStuff(); },
  ];

@dgreensp
Copy link
Contributor

dgreensp commented Mar 7, 2016

I don't think that's exactly right; you still want:

const foo = 1,
      bar = [
        2
      ];

The offending logic seems to be:

nodeIndent = nodeIndent + (indentSize * options.VariableDeclarator[parentVarNode.parent.kind]);

I'm trying to figure out what this line is supposed to do.

@dgreensp
Copy link
Contributor

dgreensp commented Mar 7, 2016

Ok, I have a PR ready for review: #5509

@gyandeeps gyandeeps 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 and removed needs info Not enough information has been provided to triage this issue triage An ESLint team member will look at this issue soon labels Mar 7, 2016
gyandeeps added a commit that referenced this issue Mar 8, 2016
Fix: overindent in VariableDeclarator parens or brackets (fixes #5492)
craigmichaelmartin pushed a commit to craigmichaelmartin/eslint that referenced this issue Mar 9, 2016
dchowitz added a commit to dchowitz/eslint that referenced this issue Mar 9, 2016
Docs: Minor README clarifications

Fixable rules are mostly limited to whitespace fixes; indicate no-reserved-keys replacement as quote-props

Fix: overindent in VariableDeclarator parens or brackets (fixes eslint#5492)

Docs: no-lone-blocks - show non-problematic (and problematic) label

Docs: Rearrange rules for better categories (and improve rule summaries)

Fix: handle personal package.json without config (fixes eslint#5496)

Docs: fix func-style arrow exception option
@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 rule Relates to ESLint's core rules
Projects
None yet
Development

No branches or pull requests

4 participants