简体   繁体   English

Prettier:防止 Prettier 删除括号

[英]Prettier : prevent Prettier of removing parentheses

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.我在一个 React Native 项目的 VSCode 中使用了 prettier,它删除了混合运算符中的括号,或者在用括号声明 var 时删除了括号。 How to prevent prettier from doing that如何防止 prettier 这样做

example1:示例 1:

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

After:

const foo = a && b || c;

example2例子2

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.我知道在大多数情况下它不会改变逻辑,但我想禁用此功能。

You can use “prettier-ignore” comments to ignore parts of files.您可以使用“prettier-ignore”注释来忽略部分文件。 Like // prettier-ignore喜欢//更漂亮-忽略

Here you have a link to documentation: https://prettier.io/docs/en/ignore.html这里有文档链接: https://prettier.io/docs/en/ignore.html

You can config it in the settings.json and add "prettier.bracketSpacing", please read here您可以在 settings.json 中配置它并添加“prettier.bracketSpacing”,请阅读此处

You can also use eslint more customizable and can use different code style like airbnb ...您还可以使用更可定制的 eslint 并且可以使用不同的代码风格,例如 airbnb ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM