Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(linter): log a message when the number of warnings exceeds the specified maxWarnings for the lint executor #27003

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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