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?
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.
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.
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.
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.
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:
But these options doesn't include what you are looking for.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With