Skip to content

Commit c7b4ec1

Browse files
committed
feat: add lint command placeholder
1 parent f853594 commit c7b4ec1

6 files changed

Lines changed: 42 additions & 2 deletions

File tree

packages/rstack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"dependencies": {
3636
"@rsbuild/core": "catalog:",
3737
"@rslib/core": "catalog:",
38+
"@rslint/core": "catalog:",
3839
"@rstest/core": "catalog:"
3940
},
4041
"devDependencies": {

packages/rstack/rslib.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export default defineConfig({
88
index: './src/index.ts',
99
rsbuildConfig: './src/rsbuildConfig.ts',
1010
rslibConfig: './src/rslibConfig.ts',
11+
rslintConfig: './src/rslintConfig.ts',
1112
rstestConfig: './src/rstestConfig.ts',
1213
test: './src/test.ts',
1314
},

packages/rstack/src/cli/commands.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Commands:
1515
build Build the app for production
1616
preview Preview the app production build locally
1717
lib Build library outputs
18+
lint Run lint checks
1819
test Run tests
1920
staged Run configured tasks on staged Git files
2021
@@ -68,6 +69,10 @@ async function runRslibCLI(args: string[]): Promise<void> {
6869
runCLI();
6970
}
7071

72+
async function runRslintCLI(): Promise<void> {
73+
// TODO
74+
}
75+
7176
export async function setupCommands(): Promise<void> {
7277
const args = process.argv.slice(2);
7378
const command = args[0];
@@ -92,6 +97,11 @@ export async function setupCommands(): Promise<void> {
9297
return;
9398
}
9499

100+
if (command === 'lint') {
101+
await runRslintCLI();
102+
return;
103+
}
104+
95105
if (command === 'staged') {
96106
await runStagedCLI(args.slice(1));
97107
return;

packages/rstack/src/config.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { loadConfig, type RsbuildConfigDefinition } from '@rsbuild/core';
22
import type { ConfigParams as RslibConfigParams, RslibConfig } from '@rslib/core';
3+
import type { defineConfig as defineRslintConfig } from '@rslint/core';
34
import type { RstestConfigExport } from '@rstest/core';
45

5-
export type ConfigType = 'app' | 'lib' | 'test' | 'staged';
6+
export type ConfigType = 'app' | 'lib' | 'test' | 'lint' | 'staged';
67

78
export type RslibConfigDefinition =
89
| RslibConfig
@@ -12,13 +13,21 @@ export type StagedTask = string | string[];
1213

1314
export type StagedConfig = Record<string, StagedTask>;
1415

15-
type Config = RsbuildConfigDefinition | RslibConfigDefinition | RstestConfigExport | StagedConfig;
16+
export type RslintConfig = Parameters<typeof defineRslintConfig>[0];
17+
18+
type Config =
19+
| RsbuildConfigDefinition
20+
| RslibConfigDefinition
21+
| RstestConfigExport
22+
| RslintConfig
23+
| StagedConfig;
1624

1725
const registry = new Map<ConfigType, Config>();
1826

1927
export function getConfig(type: 'app'): RsbuildConfigDefinition | undefined;
2028
export function getConfig(type: 'lib'): RslibConfigDefinition | undefined;
2129
export function getConfig(type: 'test'): RstestConfigExport | undefined;
30+
export function getConfig(type: 'lint'): RslintConfig | undefined;
2231
export function getConfig(type: 'staged'): StagedConfig | undefined;
2332
export function getConfig(type: ConfigType): Config | undefined {
2433
return registry.get(type);
@@ -57,6 +66,12 @@ type Define = {
5766
* `extends` is set explicitly.
5867
*/
5968
test: (config: RstestConfigExport) => void;
69+
/**
70+
* Defines the Rslint config for linting.
71+
*
72+
* This config is used by the `rs lint` command.
73+
*/
74+
lint: (config: RslintConfig) => void;
6075
/**
6176
* Defines the lint-staged config for staged files.
6277
*
@@ -69,6 +84,7 @@ export const define: Define = {
6984
app: (config) => setConfig('app', config),
7085
lib: (config) => setConfig('lib', config),
7186
test: (config) => setConfig('test', config),
87+
lint: (config) => setConfig('lint', config),
7288
staged: (config) => setConfig('staged', config),
7389
};
7490

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { getConfig, clearConfig, loadRstackConfig, type RslintConfig } from './config.js';
2+
3+
await loadRstackConfig();
4+
5+
const lintConfig: RslintConfig = getConfig('lint') ?? [];
6+
7+
clearConfig();
8+
9+
export default lintConfig;

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)