
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@code-pushup/eslint-plugin
Advanced tools
Code PushUp plugin for detecting problems in source code using ESLint.π
π΅οΈ 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:
If you haven't already, install @code-pushup/cli and create a configuration file.
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
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
. π
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 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>')),
],
};
Run the CLI with npx code-pushup collect
and view or upload report (refer to CLI docs).
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: '.eslintrc.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-*'],
},
],
},
),
],
};
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,
},
],
},
],
};
Run the CLI with npx code-pushup collect
and view or upload report (refer to CLI docs).
Find all details in our Nx setup guide.
FAQs
Code PushUp plugin for detecting problems in source code using ESLint.π
The npm package @code-pushup/eslint-plugin receives a total of 1,241 weekly downloads. As such, @code-pushup/eslint-plugin popularity was classified as popular.
We found that @code-pushup/eslint-plugin demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago.Β It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.