简体   繁体   中英

.eslintrc.json no-multi-spaces value assignment equal sign aligned javascript

We are using a pretty simple .eslintrc.json file, yet I ca't figure out the way of doing something that my IDE does automatically but then ESlint complains about.

I would like to align the equal signs below

let foo = {}

foo.one        = 1
foo.oneHundred = 100

instead of :

let foo = {}

foo.one = 1
foo.oneHundred = 100

Here is the eslint file.

{
    "extends": "standard",
    "env": {
        "es6": true,
        "node": true,
        "mocha": true
    },
    "rules": {
        "indent": ["error", 4, { "SwitchCase": 1 }],
        "quotes": ["error", "single", { "avoidEscape": true }],
        "no-multi-spaces": ["error", { "exceptions": { "ImportDeclaration": false,  "VariableDeclarator": true } }]
    }
}

Please help. ;-)

You want to use the VariableDeclarator option, as explained in the documentation: https://eslint.org/docs/rules/indent#variabledeclarator .

For your example, the indent rule could be:

"indent": [
    1,
    "tab",
    {
        "VariableDeclarator": 1, // <- What you want
        "ObjectExpression": "first",
        "ArrayExpression": "first",
        "ImportDeclaration": "first",
        "SwitchCase": 1,
        "ignoredNodes": [
            "TemplateLiteral *"
        ]
    }
],

mocha:true is the problem here if you remove it it will be working fine.

const foo = {}; 
foo.one = 1;
foo.oneHundred = 100;

you can use like that it is better.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM