Merge pull request #27456 from Glenf/feat/eslint-max-warnings-update

feat(lint): Add `--max-warnings -1` option to package lint
This commit is contained in:
Patrik Oldsberg
2024-11-08 08:20:12 +01:00
committed by GitHub
5 changed files with 23 additions and 10 deletions
+1 -1
View File
@@ -175,7 +175,7 @@ export function registerScriptCommand(program: Command) {
.option('--fix', 'Attempt to automatically fix violations')
.option(
'--max-warnings <number>',
'Fail if more than this number of warnings (default: 0)',
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
)
.description('Lint a package')
.action(lazy(() => import('./lint').then(m => m.default)));
+4 -2
View File
@@ -30,11 +30,13 @@ export default async (directories: string[], opts: OptionValues) => {
);
const maxWarnings = opts.maxWarnings ?? 0;
const ignoreWarnings = +maxWarnings === -1;
const failed =
results.some(r => r.errorCount > 0) ||
results.reduce((current, next) => current + next.warningCount, 0) >
maxWarnings;
(!ignoreWarnings &&
results.reduce((current, next) => current + next.warningCount, 0) >
maxWarnings);
if (opts.fix) {
await ESLint.outputFixes(results);
+5 -2
View File
@@ -199,11 +199,14 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
}
const maxWarnings = lintOptions?.maxWarnings ?? 0;
const ignoreWarnings = +maxWarnings === -1;
const resultText = formatter.format(results) as string;
const failed =
results.some(r => r.errorCount > 0) ||
results.reduce((current, next) => current + next.warningCount, 0) >
maxWarnings;
(!ignoreWarnings &&
results.reduce((current, next) => current + next.warningCount, 0) >
maxWarnings);
return {
relativeDir,