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

求助:.eslintrc.cjs配置规则不生效,ESLint仍触发报错

解决@typescript-eslint/no-floating-promises规则配置不生效问题

排查配置文件优先级

  • 检查项目中是否存在多个ESLint配置文件(如.eslintrc.js、.eslintrc.json或package.json中的eslintConfig字段),这类文件会按优先级覆盖.eslintrc.cjs的设置。执行npx eslint --print-config ./src/index.ts(替换为你的项目入口文件路径),查看输出结果中@typescript-eslint/no-floating-promises的实际配置,确认是否被其他配置覆盖。
  • 确保规则正确配置在rules字段下,且属于@typescript-eslint命名空间,示例格式:
    module.exports = {
      // 其他配置项
      rules: {
        "@typescript-eslint/no-floating-promises": "warn"
      }
    }
    

检查TypeScript ESLint插件版本兼容性

  • 确认@typescript-eslint/eslint-plugin与@typescript-eslint/parser的版本一致,版本不匹配可能导致规则失效。查看package.json中的依赖版本,若不一致,统一升级到相同大版本后重新安装依赖:npm install

检查extends配置的覆盖关系

  • 若extends字段中引入了plugin:@typescript-eslint/recommended等扩展配置,这类扩展可能强制将@typescript-eslint/no-floating-promises设为error。需确保rules中的规则声明在extends之后,明确覆盖扩展的设置:
    module.exports = {
      extends: [
        "eslint:recommended",
        "plugin:@typescript-eslint/recommended"
      ],
      rules: {
        "@typescript-eslint/no-floating-promises": "warn"
      }
    }
    

检查构建脚本的ESLint参数

  • 查看package.json中scripts字段的构建命令,确认是否添加了--max-warnings 0参数。该参数会将所有警告视为错误阻止构建,若存在则移除该参数,或调整为允许的警告数量。

清除ESLint缓存

  • ESLint的缓存可能导致配置修改不生效,执行npx eslint --cache --clear清除缓存后,重新运行ESLint检查。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 02:14:21