@code-pushup/eslint-plugin

中文文档
0.126.4发布于 2026/09/11MITTypeScriptES Module构建来源已验证近 30 天下载 3974

Code PushUp plugin for detecting problems in source code using ESLint.📋

原始使用文档
文档目录9 节
  1. Getting started
  2. Custom groups
  3. Optionally set up categories
  4. Artifacts generation and loading
  5. Basic artifact configuration
  6. Multiple artifact files
  7. Generate artifacts with custom command
  8. Nx Monorepo Setup
  9. Caching artifact generation

@code-pushup/eslint-plugin

npm downloads dependencies

🕵️ Code PushUp plugin for detecting problems in source code using ESLint. 📋


The plugin parses your ESLint configuration and lints targetted files using ESLint's Node.js API.

Detected ESLint rules are mapped to Code PushUp audits. Audit reports are calculated from the lint results in the following way:

  • the score is a binary "pass" or "fail" - 1 if no errors or warnings are found, otherwise 0
  • the value equals the sum of all errors and warnings
  • individual errors and warnings are mapped to issues in the audit details

Getting started

  1. If you haven't already, install @code-pushup/cli and create a configuration file.

  2. Install as a dev dependency with your package manager:

    npm install --save-dev @code-pushup/eslint-plugin
    
    yarn add --dev @code-pushup/eslint-plugin
    
    pnpm add --save-dev @code-pushup/eslint-plugin
    
  3. Prepare an ESLint configuration file with rules you're interested in measuring.

    Remember that Code PushUp only collects and uploads the results, it doesn't fail if errors are found. So you can be more strict than in most linter setups, the idea is to set aspirational goals and track your progress.

    💡 We recommend extending our own @code-pushup/eslint-config. 😇

  4. Add this plugin to the plugins array in your Code PushUp CLI config file (e.g. code-pushup.config.js).

    The simplest configuration uses default settings and lints the current directory:

    import eslintPlugin from '@code-pushup/eslint-plugin';
    
    export default {
      // ...
      plugins: [
        // ...
        await eslintPlugin(),
      ],
    };
    

    You can optionally specify a custom ESLint config file and/or glob patterns for target files (relative to process.cwd()):

    import eslintPlugin from '@code-pushup/eslint-plugin';
    
    export default {
      // ...
      plugins: [
        // ...
        await eslintPlugin({ eslintrc: './eslint.config.js', patterns: ['src/**/*.js'] }),
      ],
    };
    

    If you're using an Nx monorepo, additional helper functions are provided to simplify your configuration:

    • If you wish to combine all projects in your workspace into one report, use the eslintConfigFromAllNxProjects helper:

      import eslintPlugin, { eslintConfigFromAllNxProjects } from '@code-pushup/eslint-plugin';
      
      export default {
        plugins: [
          // ...
          await eslintPlugin(await eslintConfigFromAllNxProjects()),
        ],
      };
      

      You can also exclude specific projects if needed by passing their names in the exclude option:

      await eslintConfigFromAllNxProjects({ exclude: ['server'] });
      
    • If you wish to target a specific project along with other projects it depends on, use the eslintConfigFromNxProjectAndDeps helper and pass in in your project name:

      import eslintPlugin, { eslintConfigFromNxProjectAndDeps } from '@code-pushup/eslint-plugin';
      
      export default {
        plugins: [
          // ...
          await eslintPlugin(await eslintConfigFromNxProjectAndDeps('<PROJECT-NAME>')),
        ],
      };
      
  5. Run the CLI with npx code-pushup collect and view or upload report (refer to CLI docs).

Custom groups

You can extend the plugin configuration with custom groups to categorize ESLint rules according to your project's specific needs. Custom groups allow you to assign weights to individual rules, influencing their impact on the report. Rules can be defined as an object with explicit weights or as an array where each rule defaults to a weight of 1. Additionally, you can use wildcard patterns (*) to include multiple rules with similar prefixes.

import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
  // ...
  plugins: [
    // ...
    await eslintPlugin(
      { eslintrc: 'eslint.config.js', patterns: ['src/**/*.js'] },
      {
        groups: [
          {
            slug: 'modern-angular',
            title: 'Modern Angular',
            rules: {
              '@angular-eslint/template/prefer-control-flow': 3,
              '@angular-eslint/template/prefer-ngsrc': 2,
              '@angular-eslint/component-selector': 1,
            },
          },
          {
            slug: 'type-safety',
            title: 'Type safety',
            rules: ['@typescript-eslint/no-unsafe-*'],
          },
        ],
      },
    ),
  ],
};

Optionally set up categories

  1. Reference audits (or groups) which you wish to include in custom categories (use npx code-pushup print-config to list audits and groups).

    Assign weights based on what influence each ESLint rule should have on the overall category score (assign weight 0 to only include as extra info, without influencing category score). Note that categories can combine multiple plugins.

    export default {
      // ...
      categories: [
        {
          slug: 'code-style',
          title: 'Code style',
          refs: [
            {
              type: 'audit',
              plugin: 'eslint',
              slug: 'no-var',
              weight: 1,
            },
            {
              type: 'audit',
              plugin: 'eslint',
              slug: 'prefer-const',
              weight: 1,
            },
            {
              type: 'audit',
              plugin: 'eslint',
              slug: 'react-hooks-rules-of-hooks',
              weight: 2,
            },
            // ...
          ],
        },
        {
          slug: 'performance',
          title: 'Performance',
          refs: [
            // ... weighted performance audits (e.g. from Lighthouse) ...
            {
              type: 'audit',
              plugin: 'eslint',
              slug: 'react-jsx-key',
              weight: 0,
            },
            // ...
          ],
        },
        // ...
      ],
    };
    

    Referencing individual audits provides a lot of granularity, but it can be difficult to maintain such a configuration when there is a high amount of lint rules. A simpler way is to reference many related audits at once using groups. E.g. you can distinguish rules which have declared a type of problem, suggestion, or layout:

    export default {
      // ...
      categories: [
        {
          slug: 'bug-prevention',
          title: 'Bug prevention',
          refs: [
            {
              type: 'group',
              plugin: 'eslint',
              slug: 'problems',
              weight: 100,
            },
          ],
        },
        {
          slug: 'code-style',
          title: 'Code style',
          refs: [
            {
              type: 'group',
              plugin: 'eslint',
              slug: 'suggestions',
              weight: 75,
            },
            {
              type: 'group',
              plugin: 'eslint',
              slug: 'formatting',
              weight: 25,
            },
          ],
        },
      ],
    };
    
  2. Run the CLI with npx code-pushup collect and view or upload report (refer to CLI docs).

Artifacts generation and loading

In addition to running ESLint from the plugin implementation, you can configure the plugin to consume pre-generated ESLint reports (artifacts). This is particularly useful for:

  • CI/CD pipelines: Use cached lint results from your build system
  • Monorepo setups: Aggregate results from multiple projects or targets
  • Performance optimization: Skip ESLint execution when reports are already available
  • Custom workflows: Integrate with existing linting infrastructure

The artifacts feature supports loading ESLint JSON reports that follow the standard ESLint.LintResult[] format.

Basic artifact configuration

Specify the path(s) to your ESLint JSON report files in the artifacts option. If you don't need custom lint patterns, pass an empty object as the first parameter:

import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
  plugins: [await eslintPlugin({}, { artifacts: { artifactsPaths: './eslint-report.json' } })],
};

Multiple artifact files

Use glob patterns to aggregate results from multiple files:

export default {
  plugins: [
    await eslintPlugin(
      {},
      {
        artifacts: {
          artifactsPaths: ['packages/**/eslint-report.json', 'apps/**/.eslint/*.json'],
        },
      },
    ),
  ],
};

Generate artifacts with custom command

If you need to generate the artifacts before loading them, use the generateArtifactsCommand option:

export default {
  plugins: [
    await eslintPlugin(
      {},
      {
        artifacts: {
          generateArtifactsCommand: 'npm run lint:report',
          artifactsPaths: './eslint-report.json',
        },
      },
    ),
  ],
};

You can also specify the command with arguments:

export default {
  plugins: [
    await eslintPlugin(
      {},
      {
        artifacts: {
          generateArtifactsCommand: {
            command: 'eslint',
            args: ['src/**/*.{js,ts}', '--format=json', '--output-file=eslint-report.json'],
          },
          artifactsPaths: './eslint-report.json',
        },
      },
    ),
  ],
};

Nx Monorepo Setup

Caching artifact generation

To leverage Nx's caching capabilities, you need to generate a JSON artifact for caching, while still being able to see the ESLint violations in the terminal or CI logs, so you can fix them. This can be done by leveraging eslint formatter.

lint target from nx.json

{
  "lint": {
    "inputs": ["lint-eslint-inputs"],
    "outputs": ["{projectRoot}/.eslint/**/*"],
    "cache": true,
    "executor": "nx:run-commands",
    "options": {
      "command": "eslint",
      "args": ["{projectRoot}/**/*.ts", "{projectRoot}/package.json", "--config={projectRoot}/eslint.config.js", "--max-warnings=0", "--no-warn-ignored", "--error-on-unmatched-pattern=false", "--format=@code-pushup/eslint-formatter-multi"],
      "env": {
        "ESLINT_FORMATTER_CONFIG": "{\"outputDir\":\"{projectRoot}/.eslint\"}"
      }
    }
  }
}

As you can now generate the eslint-report.json from cache your plugin configuration can directly consume them.

code-pushup.config.ts target from nx.json

{
  "code-pushup": {
    "dependsOn": ["lint"],
    // also multiple targets can be merged into one report
    //     "dependsOn": ["lint", "lint-next"],
    "executor": "nx:run-commands",
    "options": {
      "command": "npx code-pushup",
    },
  },
}

and the project configuration leverages dependsOn to ensure the artefacts are generated when running code-pushup.

Your code-pushup.config.ts can then be configured to consume the cached artifacts:

import eslintPlugin from '@code-pushup/eslint-plugin';

export default {
  plugins: [
    await eslintPlugin({
      artifacts: {
        artifactsPaths: 'packages/**/.eslint/eslint-report-*.json',
      },
    }),
  ],
};

Find more details in our Nx setup guide.

版本与发布记录

@code-pushup/eslint-plugin 共发布 256 个版本,首次发布于 2023/12/01;过去 12 个月发布了 62 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.126.4latest2026/09/111 个月前
0.126.32026/05/195 个月前
0.126.22026/03/317 个月前
0.126.12026/03/317 个月前
0.126.02026/03/307 个月前
0.125.02026/03/277 个月前

关于 @code-pushup/eslint-plugin 的常见问题

@code-pushup/eslint-plugin 是什么?

Code PushUp plugin for detecting problems in source code using ESLint.📋

如何安装 @code-pushup/eslint-plugin?

在项目目录运行 npm install @code-pushup/eslint-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:eslint(^8.46.0 || ^9.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@code-pushup/eslint-plugin 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@code-pushup/eslint-plugin 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@code-pushup/eslint-plugin 可以商用吗?

@code-pushup/eslint-plugin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@code-pushup/eslint-plugin 的下载量有多少?

根据 npm 官方下载统计,@code-pushup/eslint-plugin 在 2026/10/10 – 2026/11/08 这 30 天内被下载 3,974 次,日均约 132 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@code-pushup/eslint-plugin 还在维护吗?

最新版本 0.126.4 发布于 2026/09/11(1 个月前);至今共发布 256 个版本,其中过去 12 个月发布了 62 个;首次发布于 2023/12/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。