Skip to content

Fixing formatting on higher-order function with template string loses indentation #241

Open
@timdp

Description

@timdp

What version of this package are you using?

v17.0.0

What operating system, Node.js, and npm version?

Node v18.6.0, npm v8.13.2, ESLint v8.20.0, prettier-eslint-cli v6.0.1

What happened?

I apologize in advance if I'm in the wrong place. My (current) best guess is that there's a bug with how this package interacts with ESLint.

I'm using prettier-eslint-cli to format my code. I'm using the config provided in this package's readme and calling prettier-eslint --write index.js. At first, I thought this was a prettier-eslint issue, but I found out that it happens when prettier-eslint calls ESLint with the Standard config (and { fix: true }).

So here goes! When I try to format this code:

module.exports =
  (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
    (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
      console.info(
        `I want this to go on a new line so I am making it long, it's ${true}`
      )
    }

(which is already properly formatted), the argument to console.info loses its indentation:

      console.info(
      `I want this to go on a new line so I am making it long, it's ${true}`
      )

What did you expect to happen?

The argument should be one nesting level deeper.

Interestingly, it appears to be related to template strings. If I use a regular string, the indentation is as intended. Additionally, ESLint itself complains about indentation if I use a regular string but not if I use a template string.

I assume the issue is either with one of the underlying rules or with ESLint itself, but I haven't dug that deep. What I do know is that ESLint with defaults formats the code more sanely:

module.exports =
  (arg1, arg2, arg3, arg4, arg5, arg6, arg7) =>
  (arg1, arg2, arg3, arg4, arg5, arg6, arg7) => {
    console.info(
      `I want this to go on a new line so I am making it long, it's ${true}`
    );
  };

This is why I'm filing it as an issue with the Standard configuration.

My best guess is that it's related to a difference in how higher-order (arrow) functions are handled, since by default, ESLint doesn't indent those as much.

I went through the names of all the rules that Standard applies but couldn't identify the one that governs this. I did try to apply the config for the indent rule separately but it didn't seem relevant.

Are you willing to submit a pull request to fix this bug?

If you tell me where to look. 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions