Skip to content

Commit

Permalink
fix(linter): log a message when the number of warnings exceeds the sp…
Browse files Browse the repository at this point in the history
…ecified maxWarnings for the lint executor
  • Loading branch information
leosvelperez committed Jul 19, 2024
1 parent 83b88a1 commit da5f683
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/eslint/src/executors/lint/lint.impl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
{
Expand Down
6 changes: 6 additions & 0 deletions packages/eslint/src/executors/lint/lint.impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down

0 comments on commit da5f683

Please sign in to comment.