Merge pull request #29024 from backstage/sennyeya/module-lint
module: make lint into a separate module
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/cli': patch
|
||||
---
|
||||
|
||||
Internal change to migrate `lint` to the new module system.
|
||||
@@ -29,5 +29,6 @@ import chalk from 'chalk';
|
||||
initializer.add(import('./modules/build/alpha'));
|
||||
initializer.add(import('./modules/migrate/alpha'));
|
||||
initializer.add(import('./modules/test/alpha'));
|
||||
initializer.add(import('./modules/lint/alpha'));
|
||||
await initializer.run();
|
||||
})();
|
||||
|
||||
@@ -31,6 +31,10 @@ import {
|
||||
registerRepoCommands as registerRepoTestCommands,
|
||||
registerPackageCommands as registerPackageTestCommands,
|
||||
} from '../modules/test';
|
||||
import {
|
||||
registerPackageCommands as registerPackageLintCommands,
|
||||
registerRepoCommands as registerRepoLintCommands,
|
||||
} from '../modules/lint';
|
||||
|
||||
export function registerRepoCommand(program: Command) {
|
||||
const command = program
|
||||
@@ -39,33 +43,7 @@ export function registerRepoCommand(program: Command) {
|
||||
|
||||
registerRepoBuildCommands(command);
|
||||
registerRepoTestCommands(command);
|
||||
|
||||
command
|
||||
.command('lint')
|
||||
.description('Lint all packages in the project')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
)
|
||||
.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
)
|
||||
.option(
|
||||
'--since <ref>',
|
||||
'Only lint packages that changed since the specified ref',
|
||||
)
|
||||
.option(
|
||||
'--successCache',
|
||||
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
|
||||
)
|
||||
.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
)
|
||||
.option('--fix', 'Attempt to automatically fix violations')
|
||||
.action(lazy(() => import('./repo/lint'), 'command'));
|
||||
registerRepoLintCommands(command);
|
||||
|
||||
command
|
||||
.command('fix')
|
||||
@@ -115,25 +93,7 @@ export function registerScriptCommand(program: Command) {
|
||||
registerPackageBuildCommands(command);
|
||||
registerPackageTestCommands(command);
|
||||
|
||||
command
|
||||
.command('lint [directories...]')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
)
|
||||
.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
)
|
||||
.option('--fix', 'Attempt to automatically fix violations')
|
||||
.option(
|
||||
'--max-warnings <number>',
|
||||
'Fail if more than this number of warnings. -1 allows warnings. (default: -1)',
|
||||
)
|
||||
.description('Lint a package')
|
||||
.action(lazy(() => import('./lint'), 'default'));
|
||||
|
||||
registerPackageLintCommands(command);
|
||||
command
|
||||
.command('clean')
|
||||
.description('Delete cache directories')
|
||||
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { createCliPlugin } from '../../wiring/factory';
|
||||
import { Command } from 'commander';
|
||||
import { lazy } from '../../lib/lazy';
|
||||
|
||||
export default createCliPlugin({
|
||||
pluginId: 'lint',
|
||||
init: async reg => {
|
||||
reg.addCommand({
|
||||
path: ['package', 'lint'],
|
||||
description: 'Lint a package',
|
||||
execute: async ({ args }) => {
|
||||
const command = new Command();
|
||||
command.arguments('[directories...]');
|
||||
command.option('--fix', 'Attempt to automatically fix violations');
|
||||
command.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
);
|
||||
command.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
);
|
||||
command.option(
|
||||
'--max-warnings <number>',
|
||||
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
|
||||
);
|
||||
command.description('Lint a package');
|
||||
command.action(
|
||||
lazy(() => import('./commands/package/lint'), 'default'),
|
||||
);
|
||||
|
||||
await command.parseAsync(args, { from: 'user' });
|
||||
},
|
||||
});
|
||||
|
||||
reg.addCommand({
|
||||
path: ['repo', 'lint'],
|
||||
description: 'Lint a repository',
|
||||
execute: async ({ args }) => {
|
||||
const command = new Command();
|
||||
command.option('--fix', 'Attempt to automatically fix violations');
|
||||
command.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
);
|
||||
command.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
);
|
||||
command.option(
|
||||
'--successCache',
|
||||
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
|
||||
);
|
||||
command.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
);
|
||||
command.option(
|
||||
'--since <ref>',
|
||||
'Only lint packages that changed since the specified ref',
|
||||
);
|
||||
command.description('Lint a repository');
|
||||
command.action(lazy(() => import('./commands/repo/lint'), 'command'));
|
||||
|
||||
await command.parseAsync(args, { from: 'user' });
|
||||
},
|
||||
});
|
||||
},
|
||||
});
|
||||
+1
-1
@@ -16,7 +16,7 @@
|
||||
|
||||
import fs from 'fs-extra';
|
||||
import { OptionValues } from 'commander';
|
||||
import { paths } from '../lib/paths';
|
||||
import { paths } from '../../../../lib/paths';
|
||||
import { ESLint } from 'eslint';
|
||||
|
||||
export default async (directories: string[], opts: OptionValues) => {
|
||||
+4
-4
@@ -24,10 +24,10 @@ import {
|
||||
BackstagePackageJson,
|
||||
Lockfile,
|
||||
} from '@backstage/cli-node';
|
||||
import { paths } from '../../lib/paths';
|
||||
import { runWorkerQueueThreads } from '../../lib/parallel';
|
||||
import { createScriptOptionsParser } from './optionsParser';
|
||||
import { SuccessCache } from '../../lib/cache/SuccessCache';
|
||||
import { paths } from '../../../../lib/paths';
|
||||
import { runWorkerQueueThreads } from '../../../../lib/parallel';
|
||||
import { createScriptOptionsParser } from '../../../../commands/repo/optionsParser';
|
||||
import { SuccessCache } from '../../../../lib/cache/SuccessCache';
|
||||
|
||||
function depCount(pkg: BackstagePackageJson) {
|
||||
const deps = pkg.dependencies ? Object.keys(pkg.dependencies).length : 0;
|
||||
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright 2025 The Backstage Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { Command } from 'commander';
|
||||
import { lazy } from '../../lib/lazy';
|
||||
|
||||
export function registerPackageCommands(command: Command) {
|
||||
command
|
||||
.command('lint [directories...]')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
)
|
||||
.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
)
|
||||
.option('--fix', 'Attempt to automatically fix violations')
|
||||
.option(
|
||||
'--max-warnings <number>',
|
||||
'Fail if more than this number of warnings. -1 allows warnings. (default: 0)',
|
||||
)
|
||||
.description('Lint a package')
|
||||
.action(lazy(() => import('./commands/package/lint'), 'default'));
|
||||
}
|
||||
|
||||
export function registerRepoCommands(command: Command) {
|
||||
command
|
||||
.command('lint')
|
||||
.description('Lint all packages in the project')
|
||||
.option(
|
||||
'--format <format>',
|
||||
'Lint report output format',
|
||||
'eslint-formatter-friendly',
|
||||
)
|
||||
.option(
|
||||
'--output-file <path>',
|
||||
'Write the lint report to a file instead of stdout',
|
||||
)
|
||||
.option(
|
||||
'--since <ref>',
|
||||
'Only lint packages that changed since the specified ref',
|
||||
)
|
||||
.option(
|
||||
'--successCache',
|
||||
'Enable success caching, which skips running tests for unchanged packages that were successful in the previous run',
|
||||
)
|
||||
.option(
|
||||
'--successCacheDir <path>',
|
||||
'Set the success cache location, (default: node_modules/.cache/backstage-cli)',
|
||||
)
|
||||
.option('--fix', 'Attempt to automatically fix violations')
|
||||
.action(lazy(() => import('./commands/repo/lint'), 'command'));
|
||||
}
|
||||
Reference in New Issue
Block a user