Separate indent options for var, let and const
See original GitHub issueIn my variable declarations, I prefer to vertically align the identifiers within each var
, let
or const
declaration, eg.
// Note: '.' below represents a tab character
var foo = 1, // <- 'foo' aligns with 'bar'
. . bar = 2;
let baz = 3, // <- 'baz' aligns with 'qux'
. . qux = 4;
const a = 5, // <- 'a' aligns with 'b'
. . . b = 6;
The following rule in ESLint@1.1.0:
"indent": [2, "tab", {"VariableDeclarator": 2}]
…yields the error Expected indentation of 2 characters but found 3. (indent)
.
This is because the const b
is indented by 3 tabs instead of 2 to maintain alignment with a
(due to the keyword const
being longer than both var
and let
).
(Note: I prefer tabs over spaces, but the same issue would apply to spaces also)
Just wondering if anyone else shares this preference (for lining up identifiers vertically), and if so, whether consideration should be given to expanding the VariableDeclarator
option to allow individually specified indents for var
, let
and const
, eg.
"indent": [2, "tab", {"VariableDeclarator": {"var": 2, "let": 2, "const": 3}}]
If not, alternatives that don’t violate the indent
rule would be either:
// VariableDeclarator: 3, with extra indentation on top lines of any var/let declarations
/* eslint indent: [2, "tab", {"VariableDeclarator": 3}]*/
var. .foo = 1, // <- Extra spacing between 'var' and 'foo'
. . . bar = 2;
let. .baz = 3, // <- Extra spacing between 'let' and 'baz'
. . . qux = 4;
const a = 5,
. . . b = 6;
// VariableDeclarator: 2, and ignore const top line alignment,
/* eslint indent: [2, "tab", {"VariableDeclarator": 2}]*/
var foo = 1,
. . bar = 2;
let baz = 3,
. . qux = 4;
const a = 5, // <- 'a' doesn't align with 'b'...
. . b = 6; // <- ...but 'b' does align with 'foo', 'bar', 'baz', etc.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:23 (13 by maintainers)
Top GitHub Comments
+1 for allowing decimal values in the interim. I’m also stuck in the situation of using 4 spaces for indentation, but want to align with the declaration. Just tested in v3.9.1 and using
1.5
doesn’t seem to work.Closed issues get lost in the backlog, and issues with a lot of old discussion already can be confusing to work with. Instead, we welcome the creation of new issues if someone wants to restart a discussion. Thanks!
On May 15, 2017 13:23, “Pavel Lysenko” notifications@github.com wrote: