Skip to content

Commit e8eedc0

Browse files
authored
docs: add rs fmt to monorepo guide (#152)
1 parent 4853d5d commit e8eedc0

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎website/docs/en/guide/monorepo.mdx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
This guide explains how to use Rstack CLI in a monorepo, including how it works with task orchestrators such as [Turborepo](https://turborepo.com/docs) and [Nx](https://nx.dev/docs/getting-started/intro).
44

5-
It covers managing Rstack dependencies, configuring lint and staged-file tasks at the root, and defining separate configurations for web applications and libraries.
5+
It covers managing Rstack dependencies, configuring lint, formatting, and staged-file tasks at the root, and defining separate configurations for web applications and libraries.
66

77
## Project structure
88

99
The recommended setup has two levels:
1010

11-
- The root manages the shared Rstack version, lint rules, and staged-file tasks.
11+
- The root manages the shared Rstack version, lint and formatting rules, and staged-file tasks.
1212
- Each application or library has its own [Rstack configuration](./configuration) for build, test, or documentation configuration.
1313

1414
```text
@@ -37,7 +37,7 @@ Project-specific dependencies, such as Rsbuild plugins and testing libraries, sh
3737

3838
## Root configuration
3939

40-
Use [`define.lint()`](./configuration#define-lint) and [`define.staged()`](./configuration#define-staged) in the root `rstack.config.ts` for checks that apply to the entire repository:
40+
Use [`define.lint()`](./configuration#define-lint), [`define.fmt()`](./configuration#define-fmt), and [`define.staged()`](./configuration#define-staged) in the root `rstack.config.ts` for checks and formatting that apply to the entire repository:
4141

4242
```ts title="rstack.config.ts"
4343
import { define } from 'rstack';
@@ -48,8 +48,14 @@ define.lint(async () => {
4848
return [js.configs.recommended, ts.configs.recommended];
4949
});
5050

51+
define.fmt({
52+
singleQuote: true,
53+
ignorePatterns: ['**/dist/**'],
54+
});
55+
5156
define.staged({
52-
'*.{js,jsx,ts,tsx,mjs,cjs}': 'rs lint',
57+
'*.{js,jsx,ts,tsx,mjs,cjs}': ['rs lint', 'rs fmt'],
58+
'*.{json,md,mdx,css,html,yml,yaml}': 'rs fmt',
5359
});
5460
```
5561

@@ -60,6 +66,8 @@ Expose these tasks through scripts in the root `package.json`:
6066
"private": true,
6167
"scripts": {
6268
"lint": "rs lint",
69+
"format": "rs fmt",
70+
"check:format": "rs fmt --check",
6371
"staged": "rs staged"
6472
}
6573
}

‎website/docs/zh/guide/monorepo.mdx‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
本指南介绍如何在 Monorepo 中使用 Rstack CLI,以及如何让它与 [Turborepo](https://turborepo.com/docs)、[Nx](https://nx.dev/docs/getting-started/intro) 等任务编排工具协同工作。
44

5-
主要内容包括管理 Rstack 依赖、在根目录统一配置代码检查和暂存文件任务,以及为 Web 应用和库项目定义独立配置。
5+
主要内容包括管理 Rstack 依赖、在根目录统一配置代码检查、格式化和暂存文件任务,以及为 Web 应用和库项目定义独立配置。
66

77
## 目录结构 \{#project-structure}
88

99
推荐使用两层配置:
1010

11-
- 根目录统一管理 Rstack 版本、lint 规则和暂存文件任务。
11+
- 根目录统一管理 Rstack 版本、lint 和格式化规则,以及暂存文件任务。
1212
- 每个应用或库使用自己的 [Rstack 配置](./configuration),定义构建、测试或文档配置。
1313

1414
```text
@@ -37,7 +37,7 @@ Rsbuild 插件、测试库等项目专属依赖,建议定义在实际使用它
3737

3838
## 根配置 \{#root-configuration}
3939

40-
在根目录的 `rstack.config.ts` 中使用 [`define.lint()`](./configuration#define-lint) 和 [`define.staged()`](./configuration#define-staged) 配置适用于整个仓库的检查:
40+
在根目录的 `rstack.config.ts` 中使用 [`define.lint()`](./configuration#define-lint)、[`define.fmt()`](./configuration#define-fmt) 和 [`define.staged()`](./configuration#define-staged),配置适用于整个仓库的检查和格式化:
4141

4242
```ts title="rstack.config.ts"
4343
import { define } from 'rstack';
@@ -48,8 +48,14 @@ define.lint(async () => {
4848
return [js.configs.recommended, ts.configs.recommended];
4949
});
5050

51+
define.fmt({
52+
singleQuote: true,
53+
ignorePatterns: ['**/dist/**'],
54+
});
55+
5156
define.staged({
52-
'*.{js,jsx,ts,tsx,mjs,cjs}': 'rs lint',
57+
'*.{js,jsx,ts,tsx,mjs,cjs}': ['rs lint', 'rs fmt'],
58+
'*.{json,md,mdx,css,html,yml,yaml}': 'rs fmt',
5359
});
5460
```
5561

@@ -60,6 +66,8 @@ define.staged({
6066
"private": true,
6167
"scripts": {
6268
"lint": "rs lint",
69+
"format": "rs fmt",
70+
"check:format": "rs fmt --check",
6371
"staged": "rs staged"
6472
}
6573
}

0 commit comments

Comments
 (0)