diff --git a/packages/cli/src/modules/lint/alpha.ts b/packages/cli/src/modules/lint/alpha.ts index 8703e73b5e..c7b9ab66ed 100644 --- a/packages/cli/src/modules/lint/alpha.ts +++ b/packages/cli/src/modules/lint/alpha.ts @@ -76,6 +76,10 @@ export default createCliPlugin({ '--since ', 'Only lint packages that changed since the specified ref', ); + command.option( + '--max-warnings ', + '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')); diff --git a/packages/cli/src/modules/lint/commands/repo/lint.ts b/packages/cli/src/modules/lint/commands/repo/lint.ts index 15a3584020..246324785e 100644 --- a/packages/cli/src/modules/lint/commands/repo/lint.ts +++ b/packages/cli/src/modules/lint/commands/repo/lint.ts @@ -111,6 +111,7 @@ export async function command(opts: OptionValues, cmd: Command): Promise { 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 { 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 { return async ({ fullDir, relativeDir, - lintOptions, parentHash, }): Promise<{ relativeDir: string; @@ -199,7 +200,6 @@ export async function command(opts: OptionValues, cmd: Command): Promise { await ESLint.outputFixes(results); } - const maxWarnings = lintOptions?.maxWarnings ?? 0; const ignoreWarnings = +maxWarnings === -1; const resultText = formatter.format(results) as string; diff --git a/packages/cli/src/modules/lint/index.ts b/packages/cli/src/modules/lint/index.ts index e2bfcd0779..5be76d8928 100644 --- a/packages/cli/src/modules/lint/index.ts +++ b/packages/cli/src/modules/lint/index.ts @@ -62,6 +62,10 @@ export function registerRepoCommands(command: Command) { '--successCacheDir ', 'Set the success cache location, (default: node_modules/.cache/backstage-cli)', ) + .option( + '--max-warnings ', + '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')); }