1
0

refactor: 精简 package.json scripts,引入 eslint-plugin-prettier 统一格式检查

删除 start/build:web/format:check,简化 check 为 typecheck+lint+test

引入 eslint-plugin-prettier 将 Prettier 集成至 ESLint,统一质量检查入口

简化 lint-staged 配置,扩展 clean 清理范围至 dist/
This commit is contained in:
2026-05-12 21:43:20 +08:00
parent 9a71b7967c
commit ad87be6956
9 changed files with 78 additions and 34 deletions

View File

@@ -548,7 +548,7 @@ bun run build
```bash
bun run clean
# 清理 .build/ 缓存和 *.bun-build 临时文件
# 清理 dist/ 构建产物、.build/ 缓存和 *.bun-build 临时文件
```
### 3.4 开发工作流
@@ -640,15 +640,14 @@ bun run test:smoke
## 代码质量
项目使用多层代码质量保障体系ESLint 类型感知规则 + Perfectionist 导入排序 + Prettier 格式化 + TypeScript 严格模式 + Git hooks 自动化。
项目使用多层代码质量保障体系ESLint 类型感知规则 + Perfectionist 导入排序 + Prettier 格式化(通过 eslint-plugin-prettier 集成至 ESLint+ TypeScript 严格模式 + Git hooks 自动化。
```bash
bun run lint # ESLint 检查(含类型感知规则、导入排序、导入验证)
bun run format:check # Prettier 格式检查
bun run lint # ESLint 检查(含类型感知规则、导入排序、导入验证、Prettier 格式
bun run format # Prettier 自动格式化
bun run typecheck # TypeScript 类型检查(含 noUnusedLocals、noPropertyAccessFromIndexSignature
bun test # 运行所有测试
bun run check # 一键运行 typecheck + lint + format:check + test
bun run check # 一键运行 typecheck + lint + test
```
`check` 是日常开发推荐的质量检查命令。
@@ -657,17 +656,18 @@ bun run check # 一键运行 typecheck + lint + format:check + test
配置文件:`eslint.config.js`
| 配置来源 | 用途 |
| ------------------------------------------------- | -------------------------------------------------- |
| `@eslint/js` recommended | JavaScript 基础规则 |
| `typescript-eslint` recommended-type-checked | TypeScript 类型感知规则no-floating-promises 等) |
| `typescript-eslint` stylistic-type-checked | TypeScript 风格规则(命名规范、语法选择等) |
| `eslint-plugin-perfectionist` recommended-natural | 导入语句和命名导出自动排序 |
| `eslint-plugin-import` | 导入路径验证、循环依赖检测、重复导入合并 |
| 配置来源 | 用途 |
| --------------------------------------------------------------- | -------------------------------------------------- |
| `@eslint/js` recommended | JavaScript 基础规则 |
| `typescript-eslint` recommended-type-checked | TypeScript 类型感知规则no-floating-promises 等) |
| `typescript-eslint` stylistic-type-checked | TypeScript 风格规则(命名规范、语法选择等) |
| `eslint-plugin-perfectionist` recommended-natural | 导入语句和命名导出自动排序 |
| `eslint-plugin-import` | 导入路径验证、循环依赖检测、重复导入合并 |
| `eslint-plugin-prettier` recommended + `eslint-config-prettier` | 将 Prettier 格式集成为 ESLint 规则,禁用冲突规则 |
### Prettier 配置
配置文件:`.prettierrc.json`
配置文件:`.prettierrc.json`,通过 `eslint-plugin-prettier` 集成为 ESLint 规则(`lint` 命令同时检查格式),也可通过 `format` 命令独立运行。
显式声明所有格式化参数(`printWidth: 120``semi: true``singleQuote: false``trailingComma: "all"``endOfLine: "lf"` 等),确保不同开发环境产出完全一致的格式化结果。
@@ -686,10 +686,10 @@ bun run check # 一键运行 typecheck + lint + format:check + test
通过 husky 在 commit 阶段自动执行检查:
| Hook | 行为 |
| ------------ | -------------------------------------------------------------- |
| `pre-commit` | lint-staged 对变更文件运行 `eslint --fix` + `prettier --write` |
| `commit-msg` | commitlint 校验提交信息格式 `类型: 简短描述` |
| Hook | 行为 |
| ------------ | -------------------------------------------------------------------------------------------------------------- |
| `pre-commit` | lint-staged 对变更文件运行 `eslint --fix`TS/TSX含 Prettier 格式修复)或 `prettier --write`MD/JSON/YAML |
| `commit-msg` | commitlint 校验提交信息格式 `类型: 简短描述` |
提交类型限定:`feat``fix``refactor``docs``style``test``chore`
@@ -698,7 +698,7 @@ bun run check # 一键运行 typecheck + lint + format:check + test
## 测试
```bash
bun run check # 日常开发(类型检查 + lint + 格式 + 单元测试)
bun run check # 日常开发(类型检查 + lint(含格式 + 单元测试)
bun run verify # 完整验证check + 构建 + smoke test
```