I'm using ESLint to make my JavaScript code style consistent. My favorite indentation level is 4 and I want my declarations style to be this:
function () {
let a = 1,
bbb = 2;
const cc = 3,
ddd = 4;
}
There is a problem though, since indent rule per each structure takes a number, which is multiplication of base indentation. If I set my basic indentation to 4, I don't seem to be able to align consts.
If I set the rule to:
"indent": ["error", 4, {"VariableDeclarator": {"const": 1}}],
The correct align will be 4 spaces:
const cc = 3,
ddd = 4;
And if I set the rule to 2:
"indent": ["error", 4, {"VariableDeclarator": {"const": 2}}],
It's going to expect 8 spaces:
const cc = 3,
ddd = 4;
It doesn't accept floating numbers. How can I align var, let and const the way I want using ESLint?
is that alignment is an arrangement of items in a line while indentation is the act of indenting or state of being indented.
Go to view option then go to indentation and you will find indent using space . Your problem should be fixed.
If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.
To temporarily turn off ESLint, you should add a block comment /* eslint-disable */ before the lines that you're interested in: /* eslint-disable */ console.
According https://eslint.org/docs/rules/indent you can use:
indent: ["error", 2, { "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }
Also you can avoid this problem using next rules: https://eslint.org/docs/rules/one-var https://eslint.org/docs/rules/one-var-declaration-per-line
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With