0.39.0 ā€¢ Published 12 days ago

@code-pushup/eslint-plugin v0.39.0

Weekly downloads
-
License
MIT
Repository
github
Last release
12 days ago

@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).

    Pass in the path to your ESLint config file, along with glob patterns for which files you wish to target (relative to process.cwd()).

    import eslintPlugin from '@code-pushup/eslint-plugin';
    
    export default {
      // ...
      plugins: [
        // ...
        await eslintPlugin({ eslintrc: '.eslintrc.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 eslintConfigFromNxProjects helper:

      import eslintPlugin, { eslintConfigFromNxProjects } from '@code-pushup/eslint-plugin';
      
      export default {
        plugins: [
          // ...
          await eslintPlugin(await eslintConfigFromNxProjects()),
        ],
      };
    • If you wish to target a specific project along with other projects it depends on, use the eslintConfigFromNxProject helper and pass in in your project name:

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

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).

Nx Monorepo Setup

Find all details in our Nx setup guide.

0.39.0

12 days ago

0.35.0

1 month ago

0.34.0

1 month ago

0.30.0-alpha

1 month ago

0.29.0

2 months ago

0.28.0

2 months ago

0.27.1

2 months ago

0.26.1

2 months ago

0.26.0

2 months ago

0.25.7

2 months ago

0.25.6

2 months ago

0.23.1

2 months ago

0.23.0

2 months ago

0.22.8

3 months ago

0.22.7

3 months ago

0.22.6

3 months ago

0.22.5

3 months ago

0.22.4

3 months ago

0.22.3

3 months ago

0.22.2

3 months ago

0.21.1

3 months ago

0.20.1

3 months ago

0.20.0

3 months ago

0.21.0

3 months ago

0.19.0

3 months ago

0.20.2

3 months ago

0.18.1

3 months ago

0.18.0

3 months ago

0.17.0

3 months ago

0.16.8

3 months ago

0.16.4

3 months ago

0.16.5

3 months ago

0.16.6

3 months ago

0.16.7

3 months ago

0.16.3

3 months ago

0.16.2

3 months ago

0.16.0

3 months ago

0.16.1

3 months ago

0.15.0

3 months ago

0.14.2

3 months ago

0.14.3

3 months ago

0.14.4

3 months ago

0.14.1

3 months ago

0.13.0

3 months ago

0.13.1

3 months ago

0.13.2

3 months ago

0.14.0

3 months ago

0.12.10

3 months ago

0.12.7

3 months ago

0.12.8

3 months ago

0.12.9

3 months ago

0.12.3

3 months ago

0.12.4

3 months ago

0.12.5

3 months ago

0.12.6

3 months ago

0.12.1

3 months ago

0.12.2

3 months ago

0.11.2

3 months ago

0.12.0

3 months ago

0.11.1

4 months ago

0.11.0

4 months ago

0.9.0

4 months ago

0.10.1

4 months ago

0.10.2

4 months ago

0.10.3

4 months ago

0.10.4

4 months ago

0.10.5

4 months ago

0.10.6

4 months ago

0.10.7

4 months ago

0.10.0

4 months ago

0.8.25

4 months ago

0.8.24

4 months ago

0.8.23

4 months ago

0.8.22

4 months ago

0.8.21

4 months ago

0.8.20

4 months ago

0.8.19

4 months ago

0.8.16

4 months ago

0.8.15

4 months ago

0.8.18

4 months ago

0.8.17

4 months ago

0.8.12

4 months ago

0.8.11

4 months ago

0.8.14

4 months ago

0.8.13

4 months ago

0.8.10

4 months ago

0.8.9

4 months ago

0.8.8

4 months ago

0.8.5

4 months ago

0.8.4

4 months ago

0.8.7

4 months ago

0.8.6

4 months ago

0.8.3

4 months ago

0.8.2

4 months ago

0.8.1

4 months ago

0.8.0

4 months ago

0.7.0

4 months ago

0.6.6

4 months ago

0.6.3

4 months ago

0.6.5

4 months ago

0.6.4

4 months ago

0.6.2

4 months ago

0.5.7

4 months ago

0.6.1

4 months ago

0.6.0

4 months ago

0.5.6

4 months ago

0.5.5

5 months ago

0.5.4

5 months ago

0.5.3

5 months ago

0.5.2

5 months ago

0.5.0

5 months ago

0.5.1

5 months ago

0.4.5

5 months ago

0.4.4

5 months ago

0.4.3

5 months ago

0.4.2

5 months ago

0.4.1

5 months ago

0.3.2

5 months ago

0.4.0

5 months ago

0.3.0

5 months ago

0.2.0

5 months ago

0.3.1

5 months ago

0.1.1

5 months ago

0.1.0

5 months ago