cli: repo lint pass --max-warnings option

Signed-off-by: Vincenzo Scamporlino <vincenzos@spotify.com>
This commit is contained in:
Vincenzo Scamporlino
2025-03-20 13:39:43 +01:00
parent 49cf8b5f91
commit db78baef26
3 changed files with 10 additions and 2 deletions
+4
View File
@@ -76,6 +76,10 @@ export default createCliPlugin({
'--since <ref>',
'Only lint packages that changed since the specified ref',
);
command.option(
'--max-warnings <number>',
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
);
command.description('Lint a repository');
command.action(lazy(() => import('./commands/repo/lint'), 'command'));
@@ -111,6 +111,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
fix: Boolean(opts.fix),
format: opts.format as string | undefined,
shouldCache: Boolean(cacheContext),
maxWarnings: Number(opts.maxWarnings) || 0,
successCache: cacheContext?.entries,
rootDir: paths.targetRoot,
},
@@ -120,6 +121,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
shouldCache,
successCache,
rootDir,
maxWarnings,
}) => {
const { ESLint } = require('eslint') as typeof import('eslint');
const crypto = require('crypto') as typeof import('crypto');
@@ -131,7 +133,6 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
return async ({
fullDir,
relativeDir,
lintOptions,
parentHash,
}): Promise<{
relativeDir: string;
@@ -199,7 +200,6 @@ export async function command(opts: OptionValues, cmd: Command): Promise<void> {
await ESLint.outputFixes(results);
}
const maxWarnings = lintOptions?.maxWarnings ?? 0;
const ignoreWarnings = +maxWarnings === -1;
const resultText = formatter.format(results) as string;
+4
View File
@@ -62,6 +62,10 @@ export function registerRepoCommands(command: Command) {
'--successCacheDir <path>',
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
)
.option(
'--max-warnings <number>',
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
)
.option('--fix', 'Attempt to automatically fix violations')
.action(lazy(() => import('./commands/repo/lint'), 'command'));
}