From ae48a15629db1e72fd5cfd63091ce84418ee1f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leosvel=20P=C3=A9rez=20Espinosa?= Date: Mon, 22 Jul 2024 15:58:01 +0200 Subject: [PATCH] fix(linter): log a message when the number of warnings exceeds the specified maxWarnings for the lint executor (#27003) ## Current Behavior ## Expected Behavior ## Related Issue(s) Fixes #26906 --- .../src/executors/lint/lint.impl.spec.ts | 32 +++++++++++++++++++ .../eslint/src/executors/lint/lint.impl.ts | 6 ++++ 2 files changed, 38 insertions(+) diff --git a/packages/eslint/src/executors/lint/lint.impl.spec.ts b/packages/eslint/src/executors/lint/lint.impl.spec.ts index 77d45ca1e4109..7ef0eba7cc752 100644 --- a/packages/eslint/src/executors/lint/lint.impl.spec.ts +++ b/packages/eslint/src/executors/lint/lint.impl.spec.ts @@ -738,6 +738,38 @@ Please see https://nx.dev/recipes/tips-n-tricks/eslint for full guidance on how expect(output.success).toBeTruthy(); }); + it('should be a failure if there are more warnings than the set maxWarnings', async () => { + mockReports = [ + { + errorCount: 0, + warningCount: 4, + results: [], + usedDeprecatedRules: [], + }, + { + errorCount: 0, + warningCount: 6, + results: [], + usedDeprecatedRules: [], + }, + ]; + setupMocks(); + const output = await lintExecutor( + createValidRunBuilderOptions({ + eslintConfig: './.eslintrc.json', + lintFilePatterns: ['includedFile1'], + format: 'json', + silent: true, + maxWarnings: 3, + }), + mockContext + ); + expect(output.success).toBe(false); + expect(console.info).toHaveBeenCalledWith( + 'ESLint found too many warnings (maximum: 3).' + ); + }); + it('should be a success if there are errors but the force flag is true', async () => { mockReports = [ { diff --git a/packages/eslint/src/executors/lint/lint.impl.ts b/packages/eslint/src/executors/lint/lint.impl.ts index 6276f1eb9684a..92e8f9f74ff5d 100644 --- a/packages/eslint/src/executors/lint/lint.impl.ts +++ b/packages/eslint/src/executors/lint/lint.impl.ts @@ -200,6 +200,12 @@ Please see https://nx.dev/recipes/tips-n-tricks/eslint for full guidance on how outputPrintInfo(totals); } + if (totals.warnings > options.maxWarnings) { + console.info( + `ESLint found too many warnings (maximum: ${options.maxWarnings}).` + ); + } + return { success: normalizedOptions.force ||