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

Angular项目全局ESLint规则配置失效问题咨询

Angular项目ESLint全局规则失效问题排查

问题根源

你全局rules里的规则被overrides块中的配置覆盖了。ESLint的overrides是针对特定文件的优先级配置,优先级高于全局规则设置。

看你的配置,overrides中针对*.ts和*.tsx文件单独设置了:

"rules": {
  "@typescript-eslint/explicit-function-return-type": "error"
}

这直接覆盖了全局rules里的"@typescript-eslint/explicit-function-return-type": "off",导致全局禁用不生效。而文件内的/* eslint-disable ... */注解优先级最高,所以能正常生效。

解决方法

根据你的需求选择任一操作:

  • 完全全局禁用该规则:移除overrides块中rules里的@typescript-eslint/explicit-function-return-type配置项,或者将其值改为off。
  • 保留特定文件的规则要求:如果只是想全局禁用,但部分文件需要保留error级别,就保留overrides里的配置,同时在需要禁用的文件内使用注解。

修正后的配置示例(以全局禁用为例):

{
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "rules": {
        // 移除该规则或改为"off"
        // "@typescript-eslint/explicit-function-return-type": "error"
      },
      "extends": [
        "plugin:@typescript-eslint/recommended",
        "plugin:@typescript-eslint/recommended-requiring-type-checking"
      ],
      "parserOptions": {
        "project": ["./tsconfig.json"]
      }
    }
  ],
  "ignorePatterns": ["node_modules/"],
  "rules": {
    "@typescript-eslint/no-empty-function": "off",
    "@typescript-eslint/no-unsafe-argument": "off",
    "@typescript-eslint/no-misused-promises": "off",
    "@typescript-eslint/explicit-module-boundary-types": "error",
    "@typescript-eslint/explicit-function-return-type": "off",
    "@typescript-eslint/unbound-method": "off",
    "@typescript-eslint/no-unsafe-assignment": "off",
    "@typescript-eslint/promise/no-floating-promises": "off",
    "@typescript-eslint/no-unsafe-member-access": "off",
    "@typescript-eslint/no-unused-vars": "off",
    "@typescript-eslint/no-var-requires": "off"
  }
}

验证方式

修改配置后,运行以下命令重新检查代码:

eslint . --ext .ts,.tsx

确认目标规则已被全局禁用。

内容的提问来源于stack exchange,提问作者Gelso77

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.13 20:23:14