From cd416dac57a3f96af5c6a994fc6c37fbd79527f1 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 12:54:48 +0200 Subject: [PATCH 01/10] docs(plugin-eslint): update main README.md --- packages/plugin-eslint/README.md | 145 ++++++++++++++++++++++++++++++- 1 file changed, 144 insertions(+), 1 deletion(-) diff --git a/packages/plugin-eslint/README.md b/packages/plugin-eslint/README.md index 75a45dc63..f3893a7b5 100644 --- a/packages/plugin-eslint/README.md +++ b/packages/plugin-eslint/README.md @@ -93,6 +93,86 @@ Detected ESLint rules are mapped to Code PushUp audits. Audit reports are calcul 5. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)). +## 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: + +```js +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: + +```js +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: + +```js +export default { + plugins: [ + await eslintPlugin({ + artifacts: { + generateArtifactsCommand: 'npm run lint:report', + artifactsPaths: './eslint-report.json', + }, + }), + ], +}; +``` + +You can also specify the command with arguments: + +```js +export default { + plugins: [ + await eslintPlugin({ + artifacts: { + generateArtifactsCommand: { + command: 'eslint', + args: ['src/**/*.{js,ts}', '--format=json', '--output-file=eslint-report.json'], + }, + artifactsPaths: './eslint-report.json', + }, + }), + ], +}; +``` + ### 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. @@ -228,4 +308,67 @@ export default { ## Nx Monorepo Setup -Find all details in our [Nx setup guide](https://github.com/code-pushup/cli/wiki/Code-PushUp-integration-guide-for-Nx-monorepos#eslint-config). +### 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, to fix them. +This can be done by leveraging eslint formatter. + +_lint target from nx.json_ + +```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=@my-org/eslint-formatter-special/src/index.js"], + "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_ + +```jsonc +{ + "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: + +```js +import eslintPlugin from '@code-pushup/eslint-plugin'; + +export default { + plugins: [ + await eslintPlugin({ + artifacts: { + artifactsPaths: 'packages/**/.eslint/eslint-report-*.json', + }, + }), + ], +}; +``` + +--- + +Find more all details in our [Nx setup guide](https://github.com/code-pushup/cli/wiki/Code-PushUp-integration-guide-for-Nx-monorepos#eslint-config). From ab2e708fa74b2fd376bb4d8ead337181756d795c Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 13:03:02 +0200 Subject: [PATCH 02/10] test(plugin-eslint-e2e): add e2e test for artifacts options --- .../artifacts-config/code-pushup.config.ts | 16 ++++ .../artifacts-config/eslint.config.cjs | 13 +++ .../fixtures/artifacts-config/src/index.js | 9 ++ .../__snapshots__/collect.e2e.test.ts.snap | 88 +++++++++++++++++++ .../tests/collect.e2e.test.ts | 28 ++++++ 5 files changed, 154 insertions(+) create mode 100644 e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts create mode 100644 e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/eslint.config.cjs create mode 100644 e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/src/index.js diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts new file mode 100644 index 000000000..5fd21a632 --- /dev/null +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts @@ -0,0 +1,16 @@ +import eslintPlugin from '@code-pushup/eslint-plugin'; + +export default { + plugins: [ + await eslintPlugin( + { patterns: ['src/*.js'] }, + { + artifacts: { + generateArtifactsCommand: + "npx eslint 'src/*.js' --fix --format json --output-file eslint-report.json", + artifactsPaths: ['./code-pushup/eslint-report.json'], + }, + }, + ), + ], +}; diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/eslint.config.cjs b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/eslint.config.cjs new file mode 100644 index 000000000..cef1161f4 --- /dev/null +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/eslint.config.cjs @@ -0,0 +1,13 @@ +/** @type {import('eslint').Linter.Config[]} */ +module.exports = [ + { + ignores: ['code-pushup.config.ts'], + }, + { + rules: { + eqeqeq: 'error', + 'max-lines': ['warn', 100], + 'no-unused-vars': 'warn', + }, + }, +]; diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/src/index.js b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/src/index.js new file mode 100644 index 000000000..39665c6ec --- /dev/null +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/src/index.js @@ -0,0 +1,9 @@ +function unusedFn() { + return '42'; +} + +module.exports = function orwell() { + if (2 + 2 == 5) { + console.log(1984); + } +}; diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index b20625b3b..be68e8ae2 100644 --- a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -225,3 +225,91 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin ], } `; + +exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin with artifacts options 1`] = ` +{ + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "ESLint rule **eqeqeq**.", + "details": { + "issues": [], + }, + "displayValue": "passed", + "docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq", + "score": 1, + "slug": "eqeqeq", + "title": "Require the use of \`===\` and \`!==\`", + "value": 0, + }, + { + "description": "ESLint rule **max-lines**. + +Custom options: + +\`\`\`json +100 +\`\`\`", + "details": { + "issues": [], + }, + "displayValue": "passed", + "docsUrl": "https://eslint.org/docs/latest/rules/max-lines", + "score": 1, + "slug": "max-lines-71b54366cb01f77b", + "title": "Enforce a maximum number of lines per file", + "value": 0, + }, + { + "description": "ESLint rule **no-unused-vars**.", + "details": { + "issues": [], + }, + "displayValue": "passed", + "docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars", + "score": 1, + "slug": "no-unused-vars", + "title": "Disallow unused variables", + "value": 0, + }, + ], + "description": "Official Code PushUp ESLint plugin", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin", + "groups": [ + { + "description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.", + "refs": [ + { + "slug": "no-unused-vars", + "weight": 1, + }, + ], + "slug": "problems", + "title": "Problems", + }, + { + "description": "Something that could be done in a better way but no errors will occur if the code isn't changed.", + "refs": [ + { + "slug": "eqeqeq", + "weight": 1, + }, + { + "slug": "max-lines-71b54366cb01f77b", + "weight": 1, + }, + ], + "slug": "suggestions", + "title": "Suggestions", + }, + ], + "icon": "eslint", + "packageName": "@code-pushup/eslint-plugin", + "slug": "eslint", + "title": "ESLint", + }, + ], +} +`; diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 98966c6b8..5ced09765 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -20,6 +20,7 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { ); const fixturesFlatConfigDir = path.join(fixturesDir, 'flat-config'); const fixturesLegacyConfigDir = path.join(fixturesDir, 'legacy-config'); + const fixturesArtifactsConfigDir = path.join(fixturesDir, 'artifacts-config'); const envRoot = path.join( E2E_ENVIRONMENTS_DIR, @@ -28,22 +29,32 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { ); const flatConfigDir = path.join(envRoot, 'flat-config'); const legacyConfigDir = path.join(envRoot, 'legacy-config'); + const artifactsConfigDir = path.join(envRoot, 'artifacts-config'); const flatConfigOutputDir = path.join(flatConfigDir, '.code-pushup'); const legacyConfigOutputDir = path.join(legacyConfigDir, '.code-pushup'); + const artifactsConfigOutputDir = path.join( + artifactsConfigDir, + '.code-pushup', + ); beforeAll(async () => { await cp(fixturesFlatConfigDir, flatConfigDir, { recursive: true }); await cp(fixturesLegacyConfigDir, legacyConfigDir, { recursive: true }); + await cp(fixturesArtifactsConfigDir, artifactsConfigDir, { + recursive: true, + }); }); afterAll(async () => { await teardownTestFolder(flatConfigDir); await teardownTestFolder(legacyConfigDir); + await teardownTestFolder(artifactsConfigDir); }); afterEach(async () => { await teardownTestFolder(flatConfigOutputDir); await teardownTestFolder(legacyConfigOutputDir); + await teardownTestFolder(artifactsConfigOutputDir); }); it('should run ESLint plugin for flat config and create report.json', async () => { @@ -80,4 +91,21 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { expect(() => reportSchema.parse(report)).not.toThrow(); expect(omitVariableReportData(report as Report)).toMatchSnapshot(); }); + + it('should run ESLint plugin with artifacts options', async () => { + const { code } = await executeProcess({ + command: 'npx', + args: ['@code-pushup/cli', 'collect', '--no-progress'], + cwd: artifactsConfigDir, + }); + + expect(code).toBe(0); + + const report = await readJsonFile( + path.join(artifactsConfigOutputDir, 'report.json'), + ); + + expect(() => reportSchema.parse(report)).not.toThrow(); + expect(omitVariableReportData(report as Report)).toMatchSnapshot(); + }); }); From 668323a05543123c9b609f7a9393e55484e05c21 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 13:22:48 +0200 Subject: [PATCH 03/10] chore: adjust lint and cp targets --- nx.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nx.json b/nx.json index e86940814..709a13c8e 100644 --- a/nx.json +++ b/nx.json @@ -184,7 +184,7 @@ }, "code-pushup-eslint": { "cache": true, - "inputs": ["code-pushup-inputs", "lint-eslint-inputs"], + "inputs": ["code-pushup-inputs"], "outputs": ["{projectRoot}/.code-pushup/eslint/runner-output.json"], "executor": "nx:run-commands", "options": { From 768d161f18d750119b3695a3686be5bebec484cd Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 13:36:03 +0200 Subject: [PATCH 04/10] docs(plugin-eslint): fix typo --- packages/plugin-eslint/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-eslint/README.md b/packages/plugin-eslint/README.md index f3893a7b5..acc031234 100644 --- a/packages/plugin-eslint/README.md +++ b/packages/plugin-eslint/README.md @@ -371,4 +371,4 @@ export default { --- -Find more all details in our [Nx setup guide](https://github.com/code-pushup/cli/wiki/Code-PushUp-integration-guide-for-Nx-monorepos#eslint-config). +Find more details in our [Nx setup guide](https://github.com/code-pushup/cli/wiki/Code-PushUp-integration-guide-for-Nx-monorepos#eslint-config). From a4e0fdbae16624e7c05eff28ddef8cfc5fc3fe95 Mon Sep 17 00:00:00 2001 From: Michael Hladky <10064416+BioPhoton@users.noreply.github.com> Date: Fri, 5 Sep 2025 17:57:25 +0200 Subject: [PATCH 05/10] Update packages/plugin-eslint/README.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Matěj Chalk <34691111+matejchalk@users.noreply.github.com> --- packages/plugin-eslint/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-eslint/README.md b/packages/plugin-eslint/README.md index acc031234..0eefc23e7 100644 --- a/packages/plugin-eslint/README.md +++ b/packages/plugin-eslint/README.md @@ -310,7 +310,7 @@ export default { ### 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, to fix them. +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_ From 0a208fe75b619760a5009e55549a4783d5fbfbff Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 18:47:22 +0200 Subject: [PATCH 06/10] refactor: update e2e test mocks --- .../mocks/fixtures/artifacts-config/code-pushup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts index 5fd21a632..cd9ab9706 100644 --- a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts @@ -7,7 +7,7 @@ export default { { artifacts: { generateArtifactsCommand: - "npx eslint 'src/*.js' --fix --format json --output-file eslint-report.json", + "npx eslint 'src/*.js' --fix --format json --output-file ./code-pushup/eslint-report.json", artifactsPaths: ['./code-pushup/eslint-report.json'], }, }, From b592539a159b5a25b82a185c0280e215d6017a02 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 18:47:32 +0200 Subject: [PATCH 07/10] docs: adjust headings --- packages/plugin-eslint/README.md | 162 +++++++++++++++---------------- 1 file changed, 81 insertions(+), 81 deletions(-) diff --git a/packages/plugin-eslint/README.md b/packages/plugin-eslint/README.md index 0eefc23e7..a1ace02ff 100644 --- a/packages/plugin-eslint/README.md +++ b/packages/plugin-eslint/README.md @@ -93,86 +93,6 @@ Detected ESLint rules are mapped to Code PushUp audits. Audit reports are calcul 5. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)). -## 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: - -```js -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: - -```js -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: - -```js -export default { - plugins: [ - await eslintPlugin({ - artifacts: { - generateArtifactsCommand: 'npm run lint:report', - artifactsPaths: './eslint-report.json', - }, - }), - ], -}; -``` - -You can also specify the command with arguments: - -```js -export default { - plugins: [ - await eslintPlugin({ - artifacts: { - generateArtifactsCommand: { - command: 'eslint', - args: ['src/**/*.{js,ts}', '--format=json', '--output-file=eslint-report.json'], - }, - artifactsPaths: './eslint-report.json', - }, - }), - ], -}; -``` - ### 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. @@ -306,6 +226,86 @@ export default { 2. Run the CLI with `npx code-pushup collect` and view or upload report (refer to [CLI docs](../cli/README.md)). +## 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: + +```js +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: + +```js +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: + +```js +export default { + plugins: [ + await eslintPlugin({ + artifacts: { + generateArtifactsCommand: 'npm run lint:report', + artifactsPaths: './eslint-report.json', + }, + }), + ], +}; +``` + +You can also specify the command with arguments: + +```js +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 @@ -324,7 +324,7 @@ _lint target from nx.json_ "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=@my-org/eslint-formatter-special/src/index.js"], + "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\"}" } From 03e3fa33becbdb67fc584190c2cea4093e8a228f Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 19:13:38 +0200 Subject: [PATCH 08/10] refactor: remove --fix form plugin config :) --- .../mocks/fixtures/artifacts-config/code-pushup.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts index cd9ab9706..284edd1a9 100644 --- a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts @@ -7,7 +7,7 @@ export default { { artifacts: { generateArtifactsCommand: - "npx eslint 'src/*.js' --fix --format json --output-file ./code-pushup/eslint-report.json", + "npx eslint 'src/*.js' --format json --output-file ./code-pushup/eslint-report.json", artifactsPaths: ['./code-pushup/eslint-report.json'], }, }, From 0e37057a475bd675f8afc0ae7c96ef918c4b0fb1 Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Fri, 5 Sep 2025 19:34:41 +0200 Subject: [PATCH 09/10] test: update snapshots --- .../__snapshots__/collect.e2e.test.ts.snap | 44 +++++++++++++++---- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index be68e8ae2..ba5147705 100644 --- a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -235,14 +235,28 @@ exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLin { "description": "ESLint rule **eqeqeq**.", "details": { - "issues": [], + "issues": [ + { + "message": "Expected '===' and instead saw '=='.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js", + "position": { + "endColumn": 15, + "endLine": 6, + "startColumn": 13, + "startLine": 6, + }, + }, + }, + ], }, - "displayValue": "passed", + "displayValue": "1 error", "docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq", - "score": 1, + "score": 0, "slug": "eqeqeq", "title": "Require the use of \`===\` and \`!==\`", - "value": 0, + "value": 1, }, { "description": "ESLint rule **max-lines**. @@ -265,14 +279,28 @@ Custom options: { "description": "ESLint rule **no-unused-vars**.", "details": { - "issues": [], + "issues": [ + { + "message": "'unusedFn' is defined but never used.", + "severity": "warning", + "source": { + "file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js", + "position": { + "endColumn": 18, + "endLine": 1, + "startColumn": 10, + "startLine": 1, + }, + }, + }, + ], }, - "displayValue": "passed", + "displayValue": "1 warning", "docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars", - "score": 1, + "score": 0, "slug": "no-unused-vars", "title": "Disallow unused variables", - "value": 0, + "value": 1, }, ], "description": "Official Code PushUp ESLint plugin", From 7f68bfb9fd4e35663f22fe161338354867007abd Mon Sep 17 00:00:00 2001 From: Michael Hladky Date: Sun, 7 Sep 2025 13:08:25 +0200 Subject: [PATCH 10/10] refactor(plugin-eslint-e2e): fix e2e test --- .../artifacts-config/code-pushup.config.ts | 4 +- .../__snapshots__/collect.e2e.test.ts.snap | 116 ++++++++++++++++++ .../tests/collect.e2e.test.ts | 2 +- 3 files changed, 119 insertions(+), 3 deletions(-) diff --git a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts index 284edd1a9..3483337ec 100644 --- a/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts +++ b/e2e/plugin-eslint-e2e/mocks/fixtures/artifacts-config/code-pushup.config.ts @@ -7,8 +7,8 @@ export default { { artifacts: { generateArtifactsCommand: - "npx eslint 'src/*.js' --format json --output-file ./code-pushup/eslint-report.json", - artifactsPaths: ['./code-pushup/eslint-report.json'], + 'npx eslint src/*.js --format json --output-file ./.code-pushup/eslint-report.json', + artifactsPaths: ['./.code-pushup/eslint-report.json'], }, }, ), diff --git a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap index ba5147705..a3de821a2 100644 --- a/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap +++ b/e2e/plugin-eslint-e2e/tests/__snapshots__/collect.e2e.test.ts.snap @@ -341,3 +341,119 @@ Custom options: ], } `; + +exports[`PLUGIN collect report with eslint-plugin NPM package > should run ESLint plugin with artifacts options and create eslint-report.json and report.json 1`] = ` +{ + "packageName": "@code-pushup/core", + "plugins": [ + { + "audits": [ + { + "description": "ESLint rule **eqeqeq**.", + "details": { + "issues": [ + { + "message": "Expected '===' and instead saw '=='.", + "severity": "error", + "source": { + "file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js", + "position": { + "endColumn": 15, + "endLine": 6, + "startColumn": 13, + "startLine": 6, + }, + }, + }, + ], + }, + "displayValue": "1 error", + "docsUrl": "https://eslint.org/docs/latest/rules/eqeqeq", + "score": 0, + "slug": "eqeqeq", + "title": "Require the use of \`===\` and \`!==\`", + "value": 1, + }, + { + "description": "ESLint rule **max-lines**. + +Custom options: + +\`\`\`json +100 +\`\`\`", + "details": { + "issues": [], + }, + "displayValue": "passed", + "docsUrl": "https://eslint.org/docs/latest/rules/max-lines", + "score": 1, + "slug": "max-lines-71b54366cb01f77b", + "title": "Enforce a maximum number of lines per file", + "value": 0, + }, + { + "description": "ESLint rule **no-unused-vars**.", + "details": { + "issues": [ + { + "message": "'unusedFn' is defined but never used.", + "severity": "warning", + "source": { + "file": "tmp/e2e/plugin-eslint-e2e/__test__/artifacts-config/src/index.js", + "position": { + "endColumn": 18, + "endLine": 1, + "startColumn": 10, + "startLine": 1, + }, + }, + }, + ], + }, + "displayValue": "1 warning", + "docsUrl": "https://eslint.org/docs/latest/rules/no-unused-vars", + "score": 0, + "slug": "no-unused-vars", + "title": "Disallow unused variables", + "value": 1, + }, + ], + "description": "Official Code PushUp ESLint plugin", + "docsUrl": "https://www.npmjs.com/package/@code-pushup/eslint-plugin", + "groups": [ + { + "description": "Code that either will cause an error or may cause confusing behavior. Developers should consider this a high priority to resolve.", + "refs": [ + { + "slug": "no-unused-vars", + "weight": 1, + }, + ], + "slug": "problems", + "title": "Problems", + }, + { + "description": "Something that could be done in a better way but no errors will occur if the code isn't changed.", + "refs": [ + { + "slug": "eqeqeq", + "weight": 1, + }, + { + "slug": "max-lines-71b54366cb01f77b", + "weight": 1, + }, + ], + "slug": "suggestions", + "title": "Suggestions", + }, + ], + "icon": "eslint", + "packageName": "@code-pushup/eslint-plugin", + "slug": "eslint", + "title": "ESLint", + }, + ], +} +`; diff --git a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts index 5ced09765..bbfada16a 100644 --- a/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts +++ b/e2e/plugin-eslint-e2e/tests/collect.e2e.test.ts @@ -92,7 +92,7 @@ describe('PLUGIN collect report with eslint-plugin NPM package', () => { expect(omitVariableReportData(report as Report)).toMatchSnapshot(); }); - it('should run ESLint plugin with artifacts options', async () => { + it('should run ESLint plugin with artifacts options and create eslint-report.json and report.json', async () => { const { code } = await executeProcess({ command: 'npx', args: ['@code-pushup/cli', 'collect', '--no-progress'],