[英]Possible to disable ESLint/Prettier rule that adds parentheses?
If I write:如果我写:
const a = 1;
const b = 1;
const c = 1;
const d = 1;
const t = a * b * (c + d) / 100;
then some rule wants to change to:然后一些规则想要更改为:
const t = (a * b * (c + d)) / 100;
// ^ ^ unwanted parentheses
I don't want the extra parentheses, but I can't figure out if it is ESLint or Prettier that adds them.我不想要额外的括号,但我不知道是 ESLint 还是 Prettier 添加了它们。 My
.eslintrc
added below:我的
.eslintrc
在下面添加:
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": ["./tsconfig.json"]
},
"plugins": ["@typescript-eslint", "prettier"],
"extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"],
"rules": {
"no-console": 1,
"prettier/prettier": 2,
"no-case-declarations": 0,
"no-extra-parens": 2,
"@typescript-eslint/no-extra-parens": 2
},
"env": {
"browser": true,
"node": true
}
}
Update更新
Here is what happens when I hover without the parentheses.这是当我没有括号的 hover 时会发生什么。
It is Prettier that adds them and it can't be disabled.添加它们的是 Prettier,它不能被禁用。 See https://github.com/prettier/prettier/issues/12554
见https://github.com/prettier/prettier/issues/12554
Prettier used to print as few parentheses as possible, then it switched to print some extra ones for readability.
Prettier 过去打印尽可能少的括号,然后为了便于阅读,它切换到打印一些额外的括号。 See the very long #187 for the full story.
完整的故事请参见很长的#187。
In the thread dprint
is suggested as an alternative to Prettier.在线程中,建议使用
dprint
作为 Prettier 的替代品。 Downgrading Prettier to the 2017 version could also be an option.将 Prettier 降级到 2017 版本也可能是一种选择。 Or perhaps there is an active fork of Prettier that doesn't add the parentheses.
或者也许有一个 Prettier 的活动分支,它没有添加括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.