How to align const indent in ESLint?

I use ESLint so that my JavaScript code style is consistent. My favorite indentation level is 4, and I want my ad style to be as follows:

function () {
    let a = 1,
        bbb = 2;

    const cc = 3,
          ddd = 4;
}

However, there is a problem because the indent rule for each structure takes a number, which is a multiplication of the base indent. If I set my main indent to 4, I didn't seem to be able to align the constants.

If I set a rule:

"indent": ["error", 4, {"VariableDeclarator": {"const": 1}}],

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}}],

8 spaces expected:

const cc = 3,
        ddd = 4;

It does not accept floating numbers. How can I align var, let and const the way I want using ESLint?

+4
2

https://eslint.org/docs/rules/indent : indent: ["error", 2, { "VariableDeclarator": { "var": 2, "let": 2, "const": 3 } }

, : https://eslint.org/docs/rules/one-var https://eslint.org/docs/rules/one-var-declaration-per-line

+1

, :

function () {
    let a = 1,
        bbb = 2;

    const 
        cc = 3,
        ddd = 4;
}
0

Source: https://habr.com/ru/post/1675962/


All Articles