Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ugly formatting of JS arithmetic operators with chained method calls #8603

Open
rjkz808 opened this issue Jun 20, 2020 · 0 comments
Open

Ugly formatting of JS arithmetic operators with chained method calls #8603

rjkz808 opened this issue Jun 20, 2020 · 0 comments
Labels
area:binary expressions area:member chains lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken

Comments

@rjkz808
Copy link

rjkz808 commented Jun 20, 2020

Prettier 2.0.5
Playground link

--parser babel

Input:

class App {
  doSomething() {
    window.addEventListener('click', () => {
      user.someValue = 1 + 1 + 1 + config.app.numbers
        .reverse()
        .findIndex((value) => user.someValue >= value);
    });
  }
}

Output:

class App {
  doSomething() {
    window.addEventListener("click", () => {
      user.someValue =
        1 +
        1 +
        1 +
        config.app.numbers
          .reverse()
          .findIndex((value) => user.someValue >= value);
    });
  }
}

Expected behavior:

I'd like Prettier to format this code the same way as my input was formatted initially. When the code has four levels of nesting (which is a common case when using ES6 classes for example), Prettier can format expression which has just a single '+' operator this way:

image

Doesn't it look ugly?

@thorn0 thorn0 added area:binary expressions area:member chains lang:javascript Issues affecting JS status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug status:needs discussion Issues needing discussion and a decision to be made before action can be taken and removed status:needs investigation Issues that need additional investigation, e.g. to understand whether the reported behavior is a bug labels Jun 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:binary expressions area:member chains lang:javascript Issues affecting JS status:needs discussion Issues needing discussion and a decision to be made before action can be taken
Projects
None yet
Development

No branches or pull requests

2 participants