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

微调ESLint配置导致检测速度骤降10倍的问题求助

ESLint配置修改后检测速度骤降10倍的排查与解决

把原ESLint配置改成更新后的版本后,代码检测速度直接慢了10倍。已经确认两种配置下遍历、检测的文件完全一致,而且VSCode里测试,两种配置都能正常捕获规则违规情况,搞不懂为啥更新后的配置这么慢。

原配置

extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:vue/vue3-strongly-recommended',
    'plugin:vuejs-accessibility/recommended'
],
plugins: ['import'],
parser: 'vue-eslint-parser',
parserOptions: {
    parser: {
        js: '@typescript-eslint/parser',
        ts: '@typescript-eslint/parser',
    },
    ecmaVersion: 2020,
},

更新后的配置

extends: [
    'plugin:@typescript-eslint/recommended',
    'plugin:vue/vue3-strongly-recommended',
    'plugin:vuejs-accessibility/recommended'
],
plugins: ['import'],
parser: 'vue-eslint-parser',
parserOptions: {
    'parser': '@typescript-eslint/parser',
    ecmaVersion: 2020,
    project: './tsconfig.eslint.json',
    sourceType: 'module',
    tsconfigRootDir: __dirname,
    'extraFileExtensions': ['.vue']
},

问题根源

核心原因是更新后的配置新增了project: './tsconfig.eslint.json'。这个选项会触发@typescript-eslint的类型检查类规则——这类规则需要TypeScript完整编译整个项目的类型信息,而非仅做语法层面的检测,计算量呈指数级上升,直接导致检测速度暴跌。

原配置没有project选项,@typescript-eslint仅运行不需要类型信息的语法规则,速度自然快很多。

优化方案

  • 缩小tsconfig.eslint的范围
    检查tsconfig.eslint.json,确保只包含需要检测的文件,用exclude排除node_modules、dist等无关目录:

    {
      "extends": "./tsconfig.json",
      "include": ["src/**/*", "*.vue"],
      "exclude": ["node_modules", "dist", "**/*.spec.ts"]
    }
    
  • 禁用不必要的类型检查规则
    如果不需要全量类型检查,可以关闭部分规则,或者改用plugin:@typescript-eslint/recommended-type-checked替代plugin:@typescript-eslint/recommended——前者仅启用关键类型检查规则,能大幅降低计算负载。

  • 调整parserOptions的文件类型指定方式
    改回原配置中按文件类型分开指定parser的写法,避免parser对所有文件做不必要的类型处理:

    parserOptions: {
        parser: {
            js: '@typescript-eslint/parser',
            ts: '@typescript-eslint/parser',
        },
        ecmaVersion: 2020,
        project: './tsconfig.eslint.json',
        sourceType: 'module',
        tsconfigRootDir: __dirname,
        extraFileExtensions: ['.vue']
    },
    
  • 启用ESLint缓存
    在ESLint配置中添加cache: true,或在检测命令后加--cache,仅重新检测修改过的文件,大幅提升后续检测速度:

    module.exports = {
      // 其他配置
      cache: true,
      cacheLocation: './node_modules/.cache/eslint'
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 22:22:18