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?
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
Maybe it's worth to try:
function () {
let a = 1,
bbb = 2;
const
cc = 3,
ddd = 4;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.