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