question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

indent option for comments

See original GitHub issue

Tell us about your environment

  • ESLint Version: v4.2.0
  • 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, { "FunctionExpression": {"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, { "FunctionExpression": {"body": 1, "parameters": 1} }]*/

define([
// Foo modules
  "bar",
// Boo modules
  "baz",
  "qux"
],

function (
// Foo modules
  bar,
// Boo modules
  baz,
  qux
) {
  qux();
});

What did you expect to happen? I expected the comment-lines “Foo modules” and “Boo modules” to get the same validation.

What actually happened? Please include the actual, raw output from ESLint. It gave me validation errors on the second comment-line “Boo modules”

   6:1  error  Expected indentation of 2 spaces but found 0  indent
  14:1  error  Expected indentation of 2 spaces but found 0  indent

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

If I run --fix it ends up looking like this, which to me is inconsistent. Preferably I’d like an option to specify where the comment should be, as I’d rather have them with 0 indent as in the original file (it makes it easier to see the difference between groups of dependencies). If that’s too much to ask, I’d like the first comment to not be treated differently from subsequent ones.

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

define([
// Foo modules - this stayed in it's place
  "bar",
  // Boo modules - this got indented 2 spaces
  "baz",
  "qux"
],

function (
// Foo modules - this stayed in it's place
  bar,
  // Boo modules - this got indented 2 spaces
  baz,
  qux
) {
  qux();
});

Note Running without the define as a simple method and using FunctionDeclaration instead works the same. I.e. “Foo modules” has no validation issue, but “Bar modules” is expecting 4 indent.

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

function foo(
// Foo modules
    bar,
// Bar modules
    baz,
    qux
) {
    qux();
}

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jul 26, 2017

@mcdoh I’ve created issue #9018, containing a proposed enhancement to ignore comment indenting entirely.

1reaction
platinumazurecommented, Jul 12, 2017

Hi @seriema, thanks for the issue.

The short answer is that we can’t always tell what tokens a comment should really be associated with. So we allow comments to be at one of three indent levels (which may overlap in some cases):

  1. Same indent as first token of previous line
  2. Same indent as first token of next line
  3. “Expected” indentation level, based on the expected indentation level of a token at the same location

I do wish we could find a way to enhance the rule to let users specify how comments should usually be handled, but the rule is already very complicated as it is. So, at this point, this is working as designed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Comments (indent: Indent and Format C Program Source)
indent attempts to leave boxed comments unmodified. The general idea of such a comment is that it is enclosed in a rectangle or...
Read more >
HTML Indentation, Spacing, and Comments
When you are writing HTML (or any other programming language), well-written code follows consistent indentation and spacing patterns.
Read more >
comment indentation can break code indentation
I have the “Indent but do not format” on paste option enabled, and I tried with “Preserve indentation of comments” both checked AND...
Read more >
Indent - Option Summary
Here is a list of all the options for indent , alphabetized by short option. It is followed by a cross key alphabetized...
Read more >
Extra Space Indent in Comments in Word - Microsoft Community
That setting really is less than useful! It is not the Comment Text style because that will not move the Author name. If...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found