Prettier : prevent Prettier of removing parentheses

Viewed 3074

I'm using prettier in VSCode on a react native project and it removes parentheses in mixed operators or when declaring a var with a parenthesis. How to prevent prettier from doing that

example1:

 const foo = (a && b) || c;

After:

const foo = a && b || c;

example2

const c = (a.toString()).toUpperCase();

After:

const c = a.toString().toUpperCase();

I know that in most cases it doesn't change the logic but I want to disable this feature.

2 Answers

You can config it in the settings.json and add "prettier.bracketSpacing", please read here

You can also use eslint more customizable and can use different code style like airbnb ...

Related