[英]Possible to disable ESLint/Prettier rule that adds parentheses?
如果我寫:
const a = 1;
const b = 1;
const c = 1;
const d = 1;
const t = a * b * (c + d) / 100;
然后一些規則想要更改為:
const t = (a * b * (c + d)) / 100;
// ^ ^ unwanted parentheses
我不想要額外的括號,但我不知道是 ESLint 還是 Prettier 添加了它們。 我的.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
}
}
更新
這是當我沒有括號的 hover 時會發生什么。
添加它們的是 Prettier,它不能被禁用。 見https://github.com/prettier/prettier/issues/12554
Prettier 過去打印盡可能少的括號,然后為了便於閱讀,它切換到打印一些額外的括號。 完整的故事請參見很長的#187。
在線程中,建議使用dprint
作為 Prettier 的替代品。 將 Prettier 降級到 2017 版本也可能是一種選擇。 或者也許有一個 Prettier 的活動分支,它沒有添加括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.