Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eslint and prettier conflict on operator-linebreak rule

I have some eslint and prettier config. When I hit ctrl + s to save my code my eslint is trying to format the code like this :

        (errors.password
            && (errors.password.type === 'minLength'
            || errors.password.type === 'maxLength') && (
              <Styled.Error className="invalidForm">
                Password must be more than 6 and less then 32 digits
              </Styled.Error>
          ))
            || (errors.password && (
              <Styled.Error className="invalidForm">
                Password is required
              </Styled.Error>
            ))

and instantly after that prettier also format code to that:

        (errors.password &&
            (errors.password.type === 'minLength' ||
              errors.password.type === 'maxLength') && (
              <Styled.Error className="invalidForm">
                Password must be more than 6 and less then 32 digits
              </Styled.Error>
            )) ||
            (errors.password && (
              <Styled.Error className="invalidForm">
                Password is required
              </Styled.Error>
            ))

I don't want to chage eslint rule, and I don't want to disable prettier format. How could I change the prettier rule for placing logic operators?

like image 756
Alex Lance Avatar asked May 22 '20 10:05

Alex Lance


People also ask

Can Prettier and ESLint work together?

Creating an ESLint and Prettier workflow setup. ESLint and Prettier files can conflict with each other because there are occasions when they end up checking the same rules which can lead to duplication. Fortunately, it is possible to get them both to work together.

Does Prettier conflict with ESLint?

You did it! In your project now you have ESLint and Prettier working perfectly at the same time. Prettier runs as a plugin of ESLint and thanks to the special configuration it won't conflict with it.

How do you make ESLint and Prettier work together?

Configuring Prettier to work with ESLint With ESLint and Prettier already installed, install these two packages as well. eslint-config-prettier : Turns off all ESLint rules that have the potential to interfere with Prettier rules. eslint-plugin-prettier : Turns Prettier rules into ESLint rules.

What does Prettier do that ESLint doesn t?

As mentioned earlier, whereas Prettier takes care of your code formatting, ESLint takes care of your code style. The former does everything automatically for you. If you have set up Prettier, you can configure it to format your file on saving it. That way, you never need to worry about your code formatting anymore.


1 Answers

According to prettier doc:

Prettier has a few options because of history. But we don’t want more of them. Prettier is not a kitchen-sink code formatter that attempts to print your code in any way you wish. It is opinionated.

Quoting the Why Prettier? page: By far the biggest reason for adopting Prettier is to stop all the on-going debates over styles.

Prettier ships with a handful of format options, some of them are:

  • Tab Width
  • Tabs
  • Semicolons
  • Quotes
  • Quote Props
  • JSX Quotes
  • Trailing Commas

But these options doesn't include what you are looking for.

like image 51
isAif Avatar answered Sep 19 '22 10:09

isAif