Skip to content

[indent] Add support for emacs-style indentation of MemberExpressions #1540

Closed
@c32hedge

Description

@c32hedge

Repro

{
  "rules": {
    "indent": "off",
    "@typescript-eslint/indent": ["error", 2, { "MemberExpression": 1 } ] // (default value)
  }
}
    cy.wrap(dataStore.getUsers()
            .map(t => t.MadeUpName[0].getAPI()
                 .then(api => apiInstances.push(api))))
      .then(() => dataStore.upload());

Expected Result

I would like an option that would keep the indentation the same as in my example code, which is what emacs does (I believe it's a function called typescript--proper-indentation in the typescript-mode major mode).

Actual Result

Currently my options are limited to specifying an absolute number of indentation levels, or turning the MemberExpression rule off. With the default value of 1, the code above gets "fixed" as:

    cy.wrap(dataStore.getUsers()
      .map(t => t.MadeUpName[0].getAPI()
        .then(api => apiInstances.push(api))))
      .then(() => dataStore.upload());

This is actually harmful, since the .map now lines up with the second .then as if .map were chained to cy.wrap instead of dataStore.getUsers().

Changing MemberExpression to a higher number doesn't help either since it will continue indenting the second .then as well, maintaining the false alignment.

Currently my only option is to use "off" for MemberExpression, but then I don't get any enforcement.

I have similar issues with the ClassProperty and AssignmentPattern AST nodes but that's probably worth discussing in a separate issue (actually, looks like the ClassProperty issue already exists: #549)

I saw an old eslint proposal for adding support for a "first" option for the MemberExpression rule (eslint/eslint#9383), but that doesn't seem to quite match what I'm looking for--none of the examples in the long thread there seem to cover my example above.

Additional Info

N/A (new feature request, not a problem with an existing rule)

Versions

package version
@typescript-eslint/eslint-plugin 2.17.0
@typescript-eslint/parser 2.17.0
TypeScript 3.5.3
ESLint 6.8.0
node 13.7.0
npm 6.13.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalThis issue is with another package, not typescript-eslint itselfpackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions