indent option for comments
See original GitHub issueTell 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:
- Created 6 years ago
- Comments:6 (4 by maintainers)
@mcdoh I’ve created issue #9018, containing a proposed enhancement to ignore comment indenting entirely.
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):
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.