You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 22:45:34