diff --git a/.changeset/loud-plants-dream.md b/.changeset/loud-plants-dream.md new file mode 100644 index 0000000000..a5099a088d --- /dev/null +++ b/.changeset/loud-plants-dream.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Add `--max-warnings -1` support to `backstage-cli package lint` diff --git a/docs/tooling/cli/03-commands.md b/docs/tooling/cli/03-commands.md index db108a2687..2da7e11ef4 100644 --- a/docs/tooling/cli/03-commands.md +++ b/docs/tooling/cli/03-commands.md @@ -92,9 +92,11 @@ Usage: backstage-cli repo lint [options] Lint all packages in the project Options: - --format Lint report output format (default: "eslint-formatter-friendly") - --since Only lint packages that changed since the specified ref - --fix Attempt to automatically fix violations + --format Lint report output format (default: "eslint-formatter-friendly") + --since Only lint packages that changed since the specified ref + --successCache Enable success caching, which skips running tests for unchanged packages that were successful in the previous run + --successCacheDir Set the success cache location, (default: node_modules/.cache/backstage-cli) + --fix Attempt to automatically fix violations ``` ## repo test @@ -185,8 +187,9 @@ Usage: backstage-cli package lint [options] Lint a package Options: - --format Lint report output format (default: "eslint-formatter-friendly") - --fix Attempt to automatically fix violations + --format Lint report output format (default: "eslint-formatter-friendly") + --fix Attempt to automatically fix violations + --max-warnings Fail if more than this number of warnings. -1 allows warnings. (default: 0) ``` ## package test diff --git a/packages/cli/src/commands/index.ts b/packages/cli/src/commands/index.ts index 674da516a8..2a77d527c1 100644 --- a/packages/cli/src/commands/index.ts +++ b/packages/cli/src/commands/index.ts @@ -175,7 +175,7 @@ export function registerScriptCommand(program: Command) { .option('--fix', 'Attempt to automatically fix violations') .option( '--max-warnings ', - '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))); diff --git a/packages/cli/src/commands/lint.ts b/packages/cli/src/commands/lint.ts index 8816221fb4..0c67d84c86 100644 --- a/packages/cli/src/commands/lint.ts +++ b/packages/cli/src/commands/lint.ts @@ -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); diff --git a/packages/cli/src/commands/repo/lint.ts b/packages/cli/src/commands/repo/lint.ts index 50ea09046b..7be021f8dd 100644 --- a/packages/cli/src/commands/repo/lint.ts +++ b/packages/cli/src/commands/repo/lint.ts @@ -199,11 +199,14 @@ export async function command(opts: OptionValues, cmd: Command): Promise { } 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,