Skip to content

Commit c843462

Browse files
chenjiahanswwind
andauthored
docs: simplify lint configuration examples (#355)
Co-authored-by: swwind <i@sww.moe>
1 parent bac3906 commit c843462

6 files changed

Lines changed: 28 additions & 60 deletions

File tree

website/docs/en/guide/cli/lint.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ rs lint --type-check
2929

3030
## Configuration
3131

32-
Configure linting through [`define.lint()`](../configuration#define-lint) in the [Rstack configuration file](/guide/configuration#configuration-file). It accepts the standard [Rslint configuration](https://rslint.rs/config/). Presets and plugins can be imported from `rstack/lint` on demand:
32+
Configure linting through [`define.lint()`](../configuration#define-lint) in the [Rstack configuration file](/guide/configuration#configuration-file). It accepts the standard [Rslint configuration](https://rslint.rs/config/). A configuration function receives all exports from `rstack/lint`, so presets and plugins do not need to be imported manually:
3333

3434
```ts title="rstack.config.ts"
3535
import { define } from 'rstack';
3636

37-
define.lint(async () => {
38-
const { js, ts } = await import('rstack/lint');
39-
40-
return [js.configs.recommended, ts.configs.recommended];
41-
});
37+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
4238
```

website/docs/en/guide/configuration.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,12 @@ If the root test configuration does not define `extends` and contains `projects`
150150
151151
### `define.lint()` \{#define-lint}
152152

153-
Defines the [Rslint configuration](https://rslint.rs/config/). Pass the configuration directly, or use an async function to load presets and plugins from `rstack/lint` on demand.
153+
Defines the [Rslint configuration](https://rslint.rs/config/). Pass the configuration directly, or use a synchronous or asynchronous function. The function receives all exports from `rstack/lint`, so presets and plugins do not need to be imported manually.
154154

155155
```ts title="rstack.config.ts"
156156
import { define } from 'rstack';
157157

158-
define.lint(async () => {
159-
const { js, ts } = await import('rstack/lint');
160-
161-
return [js.configs.recommended, ts.configs.recommended];
162-
});
158+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
163159
```
164160

165161
### `define.fmt()` \{#define-fmt}

website/docs/en/guide/monorepo.mdx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ Use [`define.lint()`](./configuration#define-lint), [`define.fmt()`](./configura
4646
```ts title="rstack.config.ts"
4747
import { define } from 'rstack';
4848

49-
define.lint(async () => {
50-
const { js, ts } = await import('rstack/lint');
51-
52-
return [js.configs.recommended, ts.configs.recommended];
53-
});
49+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
5450

5551
define.fmt({
5652
singleQuote: true,
@@ -86,20 +82,16 @@ If some projects need different lint rules, use [`files`](https://rslint.rs/conf
8682
```ts title="rstack.config.ts"
8783
import { define } from 'rstack';
8884

89-
define.lint(async () => {
90-
const { js, ts } = await import('rstack/lint');
91-
92-
return [
93-
js.configs.recommended,
94-
ts.configs.recommended,
95-
{
96-
files: ['apps/web/**/*.{ts,tsx}'],
97-
rules: {
98-
'@typescript-eslint/no-explicit-any': 'off',
99-
},
85+
define.lint(({ js, ts }) => [
86+
js.configs.recommended,
87+
ts.configs.recommendedTypeChecked,
88+
{
89+
files: ['apps/web/**/*.{ts,tsx}'],
90+
rules: {
91+
'@typescript-eslint/no-explicit-any': 'off',
10092
},
101-
];
102-
});
93+
},
94+
]);
10395
```
10496

10597
## Project configuration

website/docs/zh/guide/cli/lint.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,10 @@ rs lint --type-check
2929

3030
## 配置 \{#configuration}
3131

32-
[Rstack 配置文件](/guide/configuration#configuration-file)中通过 [`define.lint()`](../configuration#define-lint) 配置代码检查。该 API 支持标准的 [Rslint 配置](https://rslint.rs/config/)预设和插件可以从 `rstack/lint` 按需导入
32+
[Rstack 配置文件](/guide/configuration#configuration-file)中通过 [`define.lint()`](../configuration#define-lint) 配置代码检查。该 API 支持标准的 [Rslint 配置](https://rslint.rs/config/)配置函数会接收 `rstack/lint` 的全部导出,因此无需手动导入预设和插件
3333

3434
```ts title="rstack.config.ts"
3535
import { define } from 'rstack';
3636

37-
define.lint(async () => {
38-
const { js, ts } = await import('rstack/lint');
39-
40-
return [js.configs.recommended, ts.configs.recommended];
41-
});
37+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
4238
```

website/docs/zh/guide/configuration.mdx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,12 @@ define.test({
150150
151151
### `define.lint()` \{#define-lint}
152152

153-
定义 [Rslint 配置](https://rslint.rs/config/)。可以直接传入配置,也可以使用异步函数,按需从 `rstack/lint` 加载预设和插件
153+
定义 [Rslint 配置](https://rslint.rs/config/)。可以直接传入配置,也可以传入同步或异步函数。函数会接收 `rstack/lint` 的全部导出,因此无需手动导入预设和插件
154154

155155
```ts title="rstack.config.ts"
156156
import { define } from 'rstack';
157157

158-
define.lint(async () => {
159-
const { js, ts } = await import('rstack/lint');
160-
161-
return [js.configs.recommended, ts.configs.recommended];
162-
});
158+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
163159
```
164160

165161
### `define.fmt()` \{#define-fmt}

website/docs/zh/guide/monorepo.mdx

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,7 @@ Rsbuild 插件、测试库等项目专属依赖,建议定义在实际使用它
4646
```ts title="rstack.config.ts"
4747
import { define } from 'rstack';
4848

49-
define.lint(async () => {
50-
const { js, ts } = await import('rstack/lint');
51-
52-
return [js.configs.recommended, ts.configs.recommended];
53-
});
49+
define.lint(({ js, ts }) => [js.configs.recommended, ts.configs.recommendedTypeChecked]);
5450

5551
define.fmt({
5652
singleQuote: true,
@@ -86,20 +82,16 @@ define.staged({
8682
```ts title="rstack.config.ts"
8783
import { define } from 'rstack';
8884

89-
define.lint(async () => {
90-
const { js, ts } = await import('rstack/lint');
91-
92-
return [
93-
js.configs.recommended,
94-
ts.configs.recommended,
95-
{
96-
files: ['apps/web/**/*.{ts,tsx}'],
97-
rules: {
98-
'@typescript-eslint/no-explicit-any': 'off',
99-
},
85+
define.lint(({ js, ts }) => [
86+
js.configs.recommended,
87+
ts.configs.recommendedTypeChecked,
88+
{
89+
files: ['apps/web/**/*.{ts,tsx}'],
90+
rules: {
91+
'@typescript-eslint/no-explicit-any': 'off',
10092
},
101-
];
102-
});
93+
},
94+
]);
10395
```
10496

10597
## 子项目配置 \{#project-configuration}

0 commit comments

Comments
 (0)