Search code examples
javascriptreactjsreact-nativeeslintchained

Eslint indent with chained methods


How do I configure eslint to:

Promise.all(promises)
.then(() => {
  myExampleFunction()
})

instead of:

Promise.all(promises)
    .then(() => {
      myExampleFunction()
    })

We are using the following eslint packages:

"eslint": "4.12.0",
"eslint-plugin-promise": "3.6.0",
"eslint-plugin-react": "7.5.1",
"eslint-plugin-react-native": "3.2.0",

Solution

  • You can set MemberExpression to 0 as per documentation

    "Indent of 2 spaces with MemberExpression set to 0 will indent the multi-line property chains with 0 spaces." - indent - Rules

    as inline comment /*eslint indent: ["error", 2, { "MemberExpression": 0 }]*/

    in .eslintrc "rules": {"indent": ["error", 2, { "MemberExpression": 0 }]}