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.

Separate indent options for var, let and const

See original GitHub issue

In 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:23 (13 by maintainers)

github_iconTop GitHub Comments

6reactions
fastfedoracommented, Nov 7, 2016

+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.

2reactions
platinumazurecommented, May 15, 2017

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:

@platinumazure https://github.com/platinumazure Why new issue? The problem still the same.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/3339#issuecomment-301561134, or mute the thread https://github.com/notifications/unsubscribe-auth/AARWelICrxhsTckPujSFFE7s66-BSlfvks5r6JgmgaJpZM4Foan8 .

Read more comments on GitHub >

github_iconTop Results From Across the Web

How should we indent `const` declarations?
I write const repeatedly. var/let works nicely with 4 space indentation, but what if you use 2? I see a lot of code...
Read more >
Var, Let, and Const – What's the Difference?
var declarations are globally scoped or function scoped while let and const are block scoped. var variables can be updated and re-declared ...
Read more >
JavaScript: Var, Let, or Const? Which One Should you Use?
As a general rule, you should always declare variables with const, if you realize that the value of the variable needs to change,...
Read more >
indent - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
How to align const indent in ESLint? - javascript
Solution: Use a single variable, const, let statement per binding :) – Felix Kling. Apr 29, 2017 at 1:52. | Show 3 more...
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