Merge pull request #29317 from backstage/repo-lint-maxwarnings

Fix for repo lint max-warnings options
This commit is contained in:
Fredrik Adelöw
2025-03-21 14:04:05 +01:00
committed by GitHub
5 changed files with 18 additions and 4 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Fixed an issue causing the `repo lint` command to fail when the `--max-warnings` option was used.
+1
View File
@@ -452,6 +452,7 @@ Options:
--since <ref>
--successCache
--successCacheDir <path>
--max-warnings <number>
--fix
-h, --help
```
+5 -1
View File
@@ -38,7 +38,7 @@ export default createCliPlugin({
);
command.option(
'--max-warnings <number>',
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
'Fail if more than this number of warnings. -1 allows warnings. (default: -1)',
);
command.description('Lint a package');
command.action(
@@ -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: -1)',
);
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: opts.maxWarnings ?? -1,
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;
+5 -1
View File
@@ -31,7 +31,7 @@ export function registerPackageCommands(command: Command) {
.option('--fix', 'Attempt to automatically fix violations')
.option(
'--max-warnings <number>',
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
'Fail if more than this number of warnings. -1 allows warnings. (default: -1)',
)
.description('Lint a package')
.action(lazy(() => import('./commands/package/lint'), 'default'));
@@ -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: -1)',
)
.option('--fix', 'Attempt to automatically fix violations')
.action(lazy(() => import('./commands/repo/lint'), 'command'));
}