如何解决ESLint indent与@typescript-eslint/indent的缩进冲突?
解决ESLint与@typescript-eslint/indent缩进冲突问题
- 关闭基础ESLint的
indent规则,因为standard-with-typescript已集成@typescript-eslint/indent规则,两者同时启用会引发重复检查冲突。 - 在ESLint配置中指定
@typescript-eslint/indent为4个空格,与Prettier的tabWidth配置保持一致。
修改后的eslintrc.json配置如下:
{ "env": { "browser": true, "commonjs": true, "es2021": true }, "extends": "standard-with-typescript", "overrides": [], "parserOptions": { "ecmaVersion": "latest", "project": "tsconfig.json" }, "rules": { "indent": "off", "@typescript-eslint/indent": ["error", 4], "prettier/prettier": ["error", { "endOfLine": "auto" }] }, "parser": "@typescript-eslint/parser", "plugins": ["prettier"] }
说明
standard-with-typescript继承了@typescript-eslint的规则集,其中已经包含针对TypeScript代码的缩进检查逻辑。同时启用基础ESLint的indent规则,会导致同一行代码被两个规则重复校验,出现双重缩进提示。关闭基础规则后,仅保留@typescript-eslint/indent并设置为4个空格,就能和Prettier的配置统一,彻底解决冲突。
内容的提问来源于stack exchange,提问作者FlameDra
相关产品推荐
相关产品推荐

