@zealakit/css-doctor-cli 0.0.0-stage → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README_CN.md ADDED
@@ -0,0 +1,301 @@
1
+ <div align="center">
2
+
3
+ # @zealakit/css-doctor-cli
4
+
5
+ **使用原生 css-doctor 引擎的命令行 CSS 诊断工具。**
6
+
7
+ [English](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README.md) | [Tiếng Việt](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README_VI.md) | [简体中文](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README_CN.md)
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ![css doctor](https://github.com/zealakit/css-doctor/blob/main/assets/images/css-doctor.jpg)
14
+
15
+ ## 功能说明
16
+
17
+ `css-doctor check` 读取一个或多个 CSS 文件,用原生 LightningCSS 引擎解析,并输出
18
+ 终端报告(或供 CI 使用的 JSON)。
19
+
20
+ 这是**诊断**工具。它**不会**改写文件、minify CSS,也不会按页面拆分样式表。
21
+ 构建期优化请使用 Vite / Next / Nuxt / Rsbuild / Remix 适配器。
22
+
23
+ CLI 会报告:
24
+
25
+ | 类型 | 含义 |
26
+ | --- | --- |
27
+ | `syntax` | LightningCSS 语法警告 |
28
+ | `empty-rule` | 无声明且无嵌套规则的规则(疑似死代码) |
29
+ | `duplicate-selector` | 同一选择器文本出现在多个规则中 |
30
+ | `threshold` | 单文件选择器数量超过 `--threshold` |
31
+
32
+ ## 环境要求
33
+
34
+ - Node.js **≥ 18**
35
+ - 对应平台的 `@zealakit/css-doctor-binding` 原生二进制(随包安装,支持
36
+ macOS / Linux / Windows x64)
37
+
38
+ ## 安装
39
+
40
+ ### 无需安装,直接运行
41
+
42
+ ```bash
43
+ npx @zealakit/css-doctor-cli check "src/**/*.css"
44
+ ```
45
+
46
+ ### 安装到项目
47
+
48
+ ```bash
49
+ pnpm add -D @zealakit/css-doctor-cli
50
+
51
+ # 或
52
+ npm install -D @zealakit/css-doctor-cli
53
+ yarn add -D @zealakit/css-doctor-cli
54
+ ```
55
+
56
+ 安装后可通过以下方式调用:
57
+
58
+ ```bash
59
+ pnpm exec css-doctor --help
60
+ # npm
61
+ npx css-doctor --help
62
+ ```
63
+
64
+ ### package.json script
65
+
66
+ ```json
67
+ {
68
+ "scripts": {
69
+ "css:check": "css-doctor check \"src/**/*.css\"",
70
+ "css:check:ci": "css-doctor check \"src/**/*.css\" --json --threshold 500"
71
+ }
72
+ }
73
+ ```
74
+
75
+ ```bash
76
+ pnpm css:check
77
+ ```
78
+
79
+ ## 快速开始
80
+
81
+ ```bash
82
+ # 帮助 / 版本
83
+ css-doctor --help
84
+ css-doctor --version
85
+ css-doctor check --help
86
+ css-doctor health --help
87
+
88
+ # 单个文件
89
+ css-doctor check src/styles/app.css
90
+
91
+ # 多个文件
92
+ css-doctor check src/a.css src/b.css
93
+
94
+ # Glob — 请加引号,避免 shell 先展开
95
+ css-doctor check "src/**/*.css"
96
+
97
+ # 路径与 glob 混用
98
+ css-doctor check styles/global.css "components/**/*.css"
99
+
100
+ # CSS Health Score
101
+ css-doctor health "src/**/*.css"
102
+ css-doctor health "src/**/*.css" --json
103
+ css-doctor health "src/**/*.css" --fail-under 80
104
+ css-doctor check "src/**/*.css" --fail-under 85
105
+
106
+ # 基线 + 回归
107
+ css-doctor baseline create "src/**/*.css"
108
+ css-doctor baseline show
109
+ css-doctor diff "src/**/*.css" --fail-on-regression
110
+
111
+ # 优化智能
112
+ css-doctor optimize "src/**/*.css" --dry-run --explain --json
113
+ css-doctor fix --list
114
+ css-doctor fix "src/**/*.css" --dry-run --rule dead.empty-rule
115
+ ```
116
+
117
+ ## 命令:`check`
118
+
119
+ ```text
120
+ css-doctor check [patterns...] [options]
121
+ ```
122
+
123
+ | 参数 / 选项 | 说明 |
124
+ | --- | --- |
125
+ | `patterns...` | 一个或多个 CSS 路径或 glob。**必填。** |
126
+ | `-j, --json` | 向 stdout 输出结构化 `CheckReport` JSON |
127
+ | `--threshold <n>` | 当文件选择器数量超过 `<n>` 时警告(非负整数) |
128
+ | `--fail-under <n>` | 总体 Health Score `< n`(0–100)时退出码为 `1` |
129
+ | `-v, --version` | 打印 CLI 版本 |
130
+ | `-h, --help` | 打印帮助 |
131
+
132
+ ### Glob 提示
133
+
134
+ - 请给 glob 加引号:`"src/**/*.css"`。不加引号时,shell 可能先展开 `*`。
135
+ - 自动忽略 `node_modules` 与 `.git`。
136
+ - 含 glob 字符的真实文件路径(如 `src/[slug].css`)在文件存在时可直接传入。
137
+
138
+ ### 终端输出示例
139
+
140
+ ```text
141
+ css-doctor v1.0.0 · check
142
+ patterns src/**/*.css
143
+ ────────────────────────────────────────────────────────────────
144
+ SUCCESS src/styles/app.css · 12.4 KB
145
+ selectors 184 · rules 132 · declarations 421
146
+ analysis 3.2 ms · read 0.8 ms · total 4.0 ms
147
+ Top selectors
148
+ #app .card:hover
149
+ .nav-link.is-active
150
+ …
151
+
152
+ WARNING src/legacy.css · 48.1 KB
153
+ selectors 612 · rules 540 · declarations 1 204
154
+ Diagnostics
155
+ • empty-rule — Rule ".unused" has no declarations…
156
+ • duplicate-selector — Selector ".btn" is defined in multiple rules…
157
+ ────────────────────────────────────────────────────────────────
158
+ files 2 · analyzed 2 · issues 2 · …
159
+ ```
160
+
161
+ 状态含义:
162
+
163
+ | Status | 时机 |
164
+ | --- | --- |
165
+ | `SUCCESS` | 分析成功且无 issue |
166
+ | `WARNING` | 分析成功,但有 syntax / empty-rule / duplicate / threshold |
167
+ | `ERROR` | 无法读取/分析文件,或初始化失败 |
168
+
169
+ ## CI 与 JSON
170
+
171
+ ```bash
172
+ css-doctor check "src/**/*.css" --json
173
+ css-doctor check "src/**/*.css" -j --threshold 500
174
+ ```
175
+
176
+ `--json` 输出稳定的 `CheckReport`(`schemaVersion: 1`),包含:
177
+
178
+ - `success` — 仅当初始化成功且所有匹配文件都分析成功时为 `true`
179
+ - `errors` — 致命初始化错误(无 pattern、无匹配、绑定加载失败等)
180
+ - `files[]` — 每个文件的路径、大小、耗时、`issues`,以及成功时的 native `result`
181
+ - `summary` — 汇总计数(files、selectors、warnings、耗时等)
182
+
183
+ 保存报告:
184
+
185
+ ```bash
186
+ css-doctor check "src/**/*.css" --json > css-doctor-report.json
187
+ ```
188
+
189
+ ### 退出码(`check`)
190
+
191
+ | Code | 含义 |
192
+ | --- | --- |
193
+ | `0` | 初始化成功,且所有匹配文件均已读取并分析(允许 warning) |
194
+ | `1` | 初始化失败、无匹配、无法加载绑定、某文件读取/分析失败,或 `--fail-under` 未通过 |
195
+
196
+ warning / hint **不会**单独导致非零退出码,除非同时设置 `--fail-under`。
197
+ 若要在 CI 中根据 warning 失败,请解析 `--json` 中的 `summary.issues` /
198
+ `files[].issues`。
199
+
200
+ `check --json` 还会包含聚合的 `health` 字段(CSS Health Score)。
201
+
202
+ ## 命令:`health`
203
+
204
+ ```text
205
+ css-doctor health [patterns...] [options]
206
+ ```
207
+
208
+ 计算确定性的 **CSS Health Score**(0–100),覆盖五个维度:
209
+
210
+ | 维度 | 权重 | 测量内容 |
211
+ | --- | ---: | --- |
212
+ | Selector Complexity | 20% | 高特异性、深层组合/嵌套、长选择器 |
213
+ | Duplicate Rules | 20% | 重复选择器 / 同规则重复声明 |
214
+ | CSS Size Efficiency | 20% | 大样式表、重规则、选择器压力 |
215
+ | Dead CSS | 25% | 空规则、可恢复语法丢弃 |
216
+ | Variable Consistency | 15% | 重复定义 / `var()` 缺口(启发式) |
217
+
218
+ 等级:**A** 90–100 · **B** 80–89 · **C** 70–79 · **D** 60–69 · **F** 0–59。
219
+
220
+ | 选项 | 说明 |
221
+ | --- | --- |
222
+ | `-j, --json` | 稳定 health JSON(`schemaVersion: 1`) |
223
+ | `--threshold <n>` | 映射到 `manySelectors` 体积压力阈值 |
224
+ | `--fail-under <n>` | overall `< n` 时退出码为 `1`(CI 门禁) |
225
+
226
+ 该分数**不能**保证视觉/runtime 正确性。未使用变量等 finding 在静态证据不足时
227
+ 标记为 `heuristic`。
228
+
229
+ ### GitHub Actions 示例
230
+
231
+ ```yaml
232
+ - name: CSS diagnostics
233
+ run: pnpm exec css-doctor check "src/**/*.css" --json --threshold 800
234
+
235
+ - name: CSS health gate
236
+ run: pnpm exec css-doctor health "src/**/*.css" --fail-under 80
237
+
238
+ - name: CSS regression gate
239
+ run: pnpm exec css-doctor diff "src/**/*.css" --fail-on-regression --fail-on-new-errors
240
+ ```
241
+
242
+ 启用回归门禁前,请先在默认分支创建并提交 `.css-doctor/baseline.json`。
243
+
244
+ ## 命令:`baseline`
245
+
246
+ ```text
247
+ css-doctor baseline create|show|validate|remove [options]
248
+ ```
249
+
250
+ 创建版本化 JSON 基线(默认 `.css-doctor/baseline.json`),包含 Health Score、
251
+ 文件/诊断指纹(不保存 CSS 源码)。
252
+
253
+ | 子命令 | 作用 |
254
+ | --- | --- |
255
+ | `create [patterns...]` | 分析 CSS 并写入基线(`-o/--output` 可自定义路径) |
256
+ | `show` | 显示元数据与分数 |
257
+ | `validate` | 校验 schema 兼容性 |
258
+ | `remove` | 删除基线文件 |
259
+
260
+ ## 命令:`diff`
261
+
262
+ ```text
263
+ css-doctor diff [patterns...] [options]
264
+ ```
265
+
266
+ 将当前分析与基线对比;状态为
267
+ `healthy` | `improved` | `regressed` | `mixed` | `inconclusive`。
268
+
269
+ | 选项 | 说明 |
270
+ | --- | --- |
271
+ | `-b, --baseline <path>` | 基线路径(默认 `.css-doctor/baseline.json`) |
272
+ | `--fail-on-regression` | 状态为 `regressed` 或 `mixed` 时退出码为 `1` |
273
+ | `--fail-on-new-errors` | 出现新的 error 诊断时退出码为 `1` |
274
+ | `--fail-on-new-diagnostics` | 出现任意新诊断时退出码为 `1` |
275
+ | `--max-size-increase <n%>` | CSS 总字节增长超过百分比时失败 |
276
+ | `--max-new-errors <n>` / `--max-new-warnings <n>` | 新问题数量上限 |
277
+ | `--min-score <n>` | 当前 overall `< n` 时失败 |
278
+ | `-v, --verbose` / `-j, --json` | 详细输出 / 稳定 JSON(`schemaVersion: 1`) |
279
+
280
+ 诊断匹配使用 `code|path|selector|severity` 指纹,行号漂移不会把后续 finding
281
+ 全部标为“新增”。
282
+
283
+ 可选配置:`.css-doctor/config.json`。**优先级:** CLI 参数 > 配置文件 > 默认值。
284
+
285
+ ## 命令:`optimize` / `split` / `fix`
286
+
287
+ - `optimize` / `split`:优化报告与决策解释;默认 dry-run;`--write --out-dir` 写出分块。
288
+ - 指标区分消除字节与拆分重分布字节。
289
+ - `fix --list` / `--dry-run` / `--write`:默认只应用 **Safe** 修复
290
+ (`dead.empty-rule`、`duplicate.declaration`);Review/Unsafe 不会静默应用。
291
+
292
+ ## 安全与限制
293
+
294
+ - 命令名:`css-doctor`(通过 package `bin` 暴露)。
295
+ - CLI 做 **分析** 与 **评分**。页面覆盖拆分、体积预算、变量隔离属于框架适配器。
296
+ - CSS Modules / 动态 class 不在静态检查范围内。
297
+ - 需要对应平台的原生二进制;有预构建包时无需 Rust 工具链。
298
+
299
+ ## 完整文档
300
+
301
+ 项目 README:[English](https://github.com/zealakit/css-doctor/blob/main/README.md) | [Tiếng Việt](https://github.com/zealakit/css-doctor/blob/main/README_VI.md) | [简体中文](https://github.com/zealakit/css-doctor/blob/main/README_CN.md)
package/README_VI.md ADDED
@@ -0,0 +1,309 @@
1
+ <div align="center">
2
+
3
+ # @zealakit/css-doctor-cli
4
+
5
+ **Công cụ chẩn đoán CSS trên terminal bằng engine native css-doctor.**
6
+
7
+ [English](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README.md) | [Tiếng Việt](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README_VI.md) | [简体中文](https://github.com/zealakit/css-doctor/blob/main/packages/cli/README_CN.md)
8
+
9
+ </div>
10
+
11
+ ---
12
+
13
+ ![css doctor](https://github.com/zealakit/css-doctor/blob/main/assets/images/css-doctor.jpg)
14
+
15
+ ## CLI làm gì?
16
+
17
+ `css-doctor check` đọc một hoặc nhiều file CSS, parse bằng engine LightningCSS
18
+ native, rồi in báo cáo trên terminal (hoặc JSON cho CI).
19
+
20
+ Đây là công cụ **chẩn đoán**. Nó **không** ghi đè file, không minify, và không
21
+ chia stylesheet theo page. Muốn tối ưu lúc build, dùng adapter Vite / Next /
22
+ Nuxt / Rsbuild / Remix.
23
+
24
+ CLI báo cáo các loại issue:
25
+
26
+ | Loại | Ý nghĩa |
27
+ | --- | --- |
28
+ | `syntax` | Cảnh báo cú pháp từ LightningCSS |
29
+ | `empty-rule` | Rule không có declaration và không có nested rule (ứng viên dead code) |
30
+ | `duplicate-selector` | Cùng một selector xuất hiện ở nhiều rule |
31
+ | `threshold` | Số selector trong file vượt `--threshold` |
32
+
33
+ ## Yêu cầu
34
+
35
+ - Node.js **≥ 18**
36
+ - Binary native `@zealakit/css-doctor-binding` phù hợp nền tảng (cài kèm package
37
+ trên macOS / Linux / Windows x64 được hỗ trợ)
38
+
39
+ ## Cài đặt
40
+
41
+ ### Chạy một lần (không cần cài)
42
+
43
+ ```bash
44
+ npx @zealakit/css-doctor-cli check "src/**/*.css"
45
+ ```
46
+
47
+ ### Cài vào project
48
+
49
+ ```bash
50
+ pnpm add -D @zealakit/css-doctor-cli
51
+
52
+ # hoặc
53
+ npm install -D @zealakit/css-doctor-cli
54
+ yarn add -D @zealakit/css-doctor-cli
55
+ ```
56
+
57
+ Sau khi cài, gọi binary `css-doctor`:
58
+
59
+ ```bash
60
+ pnpm exec css-doctor --help
61
+ # npm
62
+ npx css-doctor --help
63
+ ```
64
+
65
+ ### Script trong package.json
66
+
67
+ ```json
68
+ {
69
+ "scripts": {
70
+ "css:check": "css-doctor check \"src/**/*.css\"",
71
+ "css:check:ci": "css-doctor check \"src/**/*.css\" --json --threshold 500"
72
+ }
73
+ }
74
+ ```
75
+
76
+ ```bash
77
+ pnpm css:check
78
+ ```
79
+
80
+ ## Bắt đầu nhanh
81
+
82
+ ```bash
83
+ # Trợ giúp / phiên bản
84
+ css-doctor --help
85
+ css-doctor --version
86
+ css-doctor check --help
87
+ css-doctor health --help
88
+
89
+ # Một file
90
+ css-doctor check src/styles/app.css
91
+
92
+ # Nhiều file
93
+ css-doctor check src/a.css src/b.css
94
+
95
+ # Glob — nhớ quote để shell không expand trước
96
+ css-doctor check "src/**/*.css"
97
+
98
+ # Trộn path và glob
99
+ css-doctor check styles/global.css "components/**/*.css"
100
+
101
+ # CSS Health Score
102
+ css-doctor health "src/**/*.css"
103
+ css-doctor health "src/**/*.css" --json
104
+ css-doctor health "src/**/*.css" --fail-under 80
105
+ css-doctor check "src/**/*.css" --fail-under 85
106
+
107
+ # Baseline + regression
108
+ css-doctor baseline create "src/**/*.css"
109
+ css-doctor baseline show
110
+ css-doctor diff "src/**/*.css" --fail-on-regression
111
+
112
+ # Optimization intelligence
113
+ css-doctor optimize "src/**/*.css" --dry-run --explain --json
114
+ css-doctor fix --list
115
+ css-doctor fix "src/**/*.css" --dry-run --rule dead.empty-rule
116
+ ```
117
+
118
+ ## Lệnh: `check`
119
+
120
+ ```text
121
+ css-doctor check [patterns...] [options]
122
+ ```
123
+
124
+ | Tham số / tùy chọn | Mô tả |
125
+ | --- | --- |
126
+ | `patterns...` | Một hoặc nhiều đường dẫn file CSS hoặc glob. **Bắt buộc.** |
127
+ | `-j, --json` | In JSON `CheckReport` ra stdout (dùng cho CI) |
128
+ | `--threshold <n>` | Cảnh báo khi file có hơn `<n>` selector (`n` là số nguyên ≥ 0) |
129
+ | `--fail-under <n>` | Exit `1` khi Health Score tổng thể `< n` (0–100) |
130
+ | `-v, --version` | In phiên bản CLI |
131
+ | `-h, --help` | In trợ giúp |
132
+
133
+ ### Mẹo dùng glob
134
+
135
+ - Luôn quote glob: `"src/**/*.css"`. Nếu không quote, shell có thể expand `*`
136
+ trước khi css-doctor nhận pattern.
137
+ - Tự bỏ qua `node_modules` và `.git`.
138
+ - Path literal chứa ký tự glob (ví dụ `src/[slug].css`) vẫn hoạt động nếu file
139
+ tồn tại và bạn truyền đúng đường dẫn file.
140
+
141
+ ### Ví dụ output terminal
142
+
143
+ ```text
144
+ css-doctor v1.0.0 · check
145
+ patterns src/**/*.css
146
+ ────────────────────────────────────────────────────────────────
147
+ SUCCESS src/styles/app.css · 12.4 KB
148
+ selectors 184 · rules 132 · declarations 421
149
+ analysis 3.2 ms · read 0.8 ms · total 4.0 ms
150
+ Top selectors
151
+ #app .card:hover
152
+ .nav-link.is-active
153
+ …
154
+
155
+ WARNING src/legacy.css · 48.1 KB
156
+ selectors 612 · rules 540 · declarations 1 204
157
+ Diagnostics
158
+ • empty-rule — Rule ".unused" has no declarations…
159
+ • duplicate-selector — Selector ".btn" is defined in multiple rules…
160
+ ────────────────────────────────────────────────────────────────
161
+ files 2 · analyzed 2 · issues 2 · …
162
+ ```
163
+
164
+ Trạng thái:
165
+
166
+ | Status | Khi nào |
167
+ | --- | --- |
168
+ | `SUCCESS` | Phân tích OK, không có issue |
169
+ | `WARNING` | Phân tích OK, có syntax / empty-rule / duplicate / threshold |
170
+ | `ERROR` | Không đọc/analyze được file, hoặc lỗi setup |
171
+
172
+ ## CI và JSON
173
+
174
+ ```bash
175
+ css-doctor check "src/**/*.css" --json
176
+ css-doctor check "src/**/*.css" -j --threshold 500
177
+ ```
178
+
179
+ `--json` xuất `CheckReport` ổn định (`schemaVersion: 1`) gồm:
180
+
181
+ - `success` — `true` chỉ khi setup OK và mọi file khớp đều analyze được
182
+ - `errors` — lỗi setup nghiêm trọng (không có pattern, không khớp file, không
183
+ load được binding, …)
184
+ - `files[]` — từng file: path, size, timing, `issues`, và `result` native khi `ok`
185
+ - `summary` — tổng hợp (files, selectors, warnings, timing, …)
186
+
187
+ Lưu report:
188
+
189
+ ```bash
190
+ css-doctor check "src/**/*.css" --json > css-doctor-report.json
191
+ ```
192
+
193
+ ### Exit code (`check`)
194
+
195
+ | Code | Ý nghĩa |
196
+ | --- | --- |
197
+ | `0` | Setup OK và mọi file khớp đều đọc + analyze được (warning vẫn được phép) |
198
+ | `1` | Lỗi setup, không khớp file, không load binding, file đọc/analyze thất bại, hoặc `--fail-under` không đạt |
199
+
200
+ Warning / hint **không** làm fail process trừ khi bạn cũng đặt `--fail-under`.
201
+ Muốn gate CI theo warning, dùng `--json` rồi kiểm tra `summary.issues` /
202
+ `files[].issues`.
203
+
204
+ `check --json` còn kèm field `health` (CSS Health Score tổng hợp).
205
+
206
+ ## Lệnh: `health`
207
+
208
+ ```text
209
+ css-doctor health [patterns...] [options]
210
+ ```
211
+
212
+ Tính **CSS Health Score** (0–100) theo năm chiều:
213
+
214
+ | Chiều | Trọng số | Đo lường |
215
+ | --- | ---: | --- |
216
+ | Selector Complexity | 20% | Specificity cao, combinator/nesting sâu, chuỗi dài |
217
+ | Duplicate Rules | 20% | Selector lặp / declaration trùng trong cùng rule |
218
+ | CSS Size Efficiency | 20% | Sheet lớn, rule nặng, áp lực số selector |
219
+ | Dead CSS | 25% | Rule rỗng, cú pháp bị bỏ qua khi recover |
220
+ | Variable Consistency | 15% | Định nghĩa trùng / `var()` thiếu (heuristic) |
221
+
222
+ Xếp hạng: **A** 90–100 · **B** 80–89 · **C** 70–79 · **D** 60–69 · **F** 0–59.
223
+
224
+ | Tùy chọn | Mô tả |
225
+ | --- | --- |
226
+ | `-j, --json` | JSON health ổn định (`schemaVersion: 1`) |
227
+ | `--threshold <n>` | Ánh xạ sang ngưỡng `manySelectors` |
228
+ | `--fail-under <n>` | Exit `1` khi overall `< n` (cổng CI) |
229
+
230
+ Điểm **không** đảm bảo CSS đúng về mặt hình ảnh runtime. Finding kiểu
231
+ unused-variable được gắn `heuristic` khi bằng chứng tĩnh chưa đủ.
232
+
233
+ ### GitHub Actions (ví dụ)
234
+
235
+ ```yaml
236
+ - name: CSS diagnostics
237
+ run: pnpm exec css-doctor check "src/**/*.css" --json --threshold 800
238
+
239
+ - name: CSS health gate
240
+ run: pnpm exec css-doctor health "src/**/*.css" --fail-under 80
241
+
242
+ - name: CSS regression gate
243
+ run: pnpm exec css-doctor diff "src/**/*.css" --fail-on-regression --fail-on-new-errors
244
+ ```
245
+
246
+ Hãy khởi tạo và commit `.css-doctor/baseline.json` trên nhánh mặc định trước khi
247
+ bật regression gate.
248
+
249
+ ## Lệnh: `baseline`
250
+
251
+ ```text
252
+ css-doctor baseline create|show|validate|remove [options]
253
+ ```
254
+
255
+ Tạo baseline JSON có version (mặc định `.css-doctor/baseline.json`) gồm điểm
256
+ Health Score, fingerprint file/diagnostic (không lưu source CSS).
257
+
258
+ | Subcommand | Mục đích |
259
+ | --- | --- |
260
+ | `create [patterns...]` | Analyze CSS và ghi baseline (`-o/--output` để đổi path) |
261
+ | `show` | Hiển thị metadata và điểm |
262
+ | `validate` | Kiểm tra tương thích schema |
263
+ | `remove` | Xóa file baseline |
264
+
265
+ ## Lệnh: `diff`
266
+
267
+ ```text
268
+ css-doctor diff [patterns...] [options]
269
+ ```
270
+
271
+ So sánh phân tích hiện tại với baseline; status:
272
+ `healthy` | `improved` | `regressed` | `mixed` | `inconclusive`.
273
+
274
+ | Tùy chọn | Mô tả |
275
+ | --- | --- |
276
+ | `-b, --baseline <path>` | Path baseline (mặc định `.css-doctor/baseline.json`) |
277
+ | `--fail-on-regression` | Exit `1` khi status `regressed` hoặc `mixed` |
278
+ | `--fail-on-new-errors` | Exit `1` khi có diagnostic error mới |
279
+ | `--fail-on-new-diagnostics` | Exit `1` khi có bất kỳ diagnostic mới |
280
+ | `--max-size-increase <n%>` | Fail khi tổng byte CSS tăng vượt phần trăm |
281
+ | `--max-new-errors <n>` / `--max-new-warnings <n>` | Giới hạn số issue mới |
282
+ | `--min-score <n>` | Fail khi overall hiện tại `< n` |
283
+ | `-v, --verbose` / `-j, --json` | Chi tiết / JSON ổn định (`schemaVersion: 1`) |
284
+
285
+ Diagnostic được khớp bằng fingerprint `code|path|selector|severity` nên lệch số
286
+ dòng không làm mọi finding trở thành “mới”.
287
+
288
+ Config tùy chọn: `.css-doctor/config.json`. **Thứ tự ưu tiên:** flag CLI >
289
+ config > mặc định.
290
+
291
+ ## Lệnh: `optimize` / `split` / `fix`
292
+
293
+ - `optimize` / `split`: báo cáo tối ưu + giải thích quyết định; mặc định dry-run;
294
+ `--write --out-dir` để ghi chunk.
295
+ - Metric tách byte loại bỏ khỏi byte phân tán do split.
296
+ - `fix --list` / `fix --dry-run` / `fix --write`: chỉ áp dụng fix **Safe**
297
+ (`dead.empty-rule`, `duplicate.declaration`). Review/Unsafe không áp dụng im lặng.
298
+
299
+ ## An toàn và giới hạn
300
+
301
+ - Tên binary: `css-doctor` (trường `bin` của package).
302
+ - CLI **phân tích** và **chấm điểm** CSS. Page-coverage split / size budget /
303
+ tách biến cho bundle thuộc adapter framework.
304
+ - CSS Modules / class động nằm ngoài phạm vi check tĩnh.
305
+ - Cần binary native đúng nền tảng; không cần Rust toolchain khi đã có prebuild.
306
+
307
+ ## Tài liệu đầy đủ
308
+
309
+ README dự án: [English](https://github.com/zealakit/css-doctor/blob/main/README.md) | [Tiếng Việt](https://github.com/zealakit/css-doctor/blob/main/README_VI.md) | [简体中文](https://github.com/zealakit/css-doctor/blob/main/README_CN.md)