chore: add lefthook#17847
Conversation
## Walkthrough
本次更新将项目的 Git 钩子管理工具从 Husky 和 lint-staged 切换为 Lefthook。删除了原有的 Husky 钩子脚本和 lint-staged 配置,新增了 Lefthook 的配置文件,并在 package.json 中替换相关依赖和脚本。
## Changes
| 文件/路径 | 变更摘要 |
|-----------------------------------|------------------------------------------------------------------|
| .husky/commit-msg<br>.husky/pre-commit | 删除 Husky 钩子脚本(commit-msg、pre-commit) |
| lefthook.yml | 新增 Lefthook 配置文件,定义 pre-commit、prepare-commit-msg、commit-msg、post-merge、post-checkout 钩子及相关任务 |
| package.json | 移除 Husky 和 lint-staged 依赖及配置,新增 Lefthook 和 czg 依赖,更新 prepare 脚本及新增 commit 脚本 |
## Sequence Diagram(s)
```mermaid
sequenceDiagram
participant Developer
participant Git
participant Lefthook
Developer->>Git: git commit
Git->>Lefthook: 触发 pre-commit 钩子
Lefthook->>Lefthook: 并行执行格式化、静态分析等任务
Lefthook->>Git: 完成 pre-commit
Git->>Lefthook: 触发 prepare-commit-msg/commit-msg 钩子
Lefthook->>Lefthook: 运行 git-cz/commitlint 校验
Lefthook->>Git: 完成 commitPoem
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
lefthook.yml (2)
24-34: 整理或移除已注释的测试任务
当前预留的类型检查和单元测试任务被注释,建议要么清理无用代码,要么以明确 TODO 形式保留并规划何时启用。
68-68: 添加文件末尾换行
YAML 最后一行缺少换行符,建议补充空白行以符合 POSIX 标准并避免一些解析器警告。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (4)
.husky/commit-msg(0 hunks).husky/pre-commit(0 hunks)lefthook.yml(1 hunks)package.json(2 hunks)
💤 Files with no reviewable changes (2)
- .husky/commit-msg
- .husky/pre-commit
🧰 Additional context used
🪛 YAMLlint (1.37.1)
lefthook.yml
[error] 1-1: wrong new line character: expected \n
(new-lines)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)
⏰ Context from checks skipped due to timeout of 90000ms (6)
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (4)
package.json (2)
22-22: 确认 Prepare 脚本的跨平台兼容性
当前的prepare脚本在 Windows 环境下的引号转义和命令执行可能存在问题,请在不同操作系统上验证该脚本行为,或考虑使用更安全的跨平台方案(如shx或cross-env)。
135-135: 验证已彻底移除 Husky 与 lint-staged 的引用
新增了lefthook依赖后,请检查是否在其他脚本、CI 配置或文档中仍残留旧的husky/lint-staged相关命令,并移除不再使用的依赖与配置。lefthook.yml (2)
1-3: 验证 Schema 路径与注释准确性
请确认$schema路径./node_modules/lefthook/schema.json在项目根目录结构中可访问,以及首行注释不会影响 YAML 解析。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 1-1: wrong new line character: expected \n
(new-lines)
64-68: 校验post-checkout占位符使用
{1}、{2}、{3}分别代表旧提交、当前提交和分支变化标识,建议确认 Lefthook 文档中对应钩子参数位置是否与此处一致,确保钩子逻辑生效。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project check has failed because the head coverage (55.90%) is below the target coverage (75.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #17847 +/- ##
========================================
Coverage 55.90% 55.90%
========================================
Files 417 417
Lines 21693 21693
Branches 5376 5360 -16
========================================
Hits 12127 12127
- Misses 7935 8093 +158
+ Partials 1631 1473 -158
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
做这个改动的初衷是什么?如不是必须的,或者仅仅是个人倾向,建议先不要动。 |
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
lefthook.yml (4)
4-23: 预提交钩子配置
pre-commit 钩子已配置多任务并行格式化与静态检查,逻辑清晰且符合常见最佳实践。可根据项目目录结构将 glob 模式调整为
**/*.{json,ts,tsx,js,jsx,mjs,mts,css,scss},以确保子目录文件也被处理。
24-34: 注释的测试配置
当前保留了大段注释的测试任务。若无近期启用计划,建议移除或在 PR 描述中补充后续启用时机,避免长期残留冗余注释。
1-1: 修复换行符
文件首行似乎使用了错误的新行字符(CRLF),请统一为 LF (\n)。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 1-1: wrong new line character: expected \n
(new-lines)
68-68: 添加文件末尾换行
请在文件末尾添加一个空的新行以满足 POSIX 文档规范。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
pnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (2)
lefthook.yml(1 hunks)package.json(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- package.json
🧰 Additional context used
🪛 YAMLlint (1.37.1)
lefthook.yml
[error] 1-1: wrong new line character: expected \n
(new-lines)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)
⏰ Context from checks skipped due to timeout of 90000ms (5)
- GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
- GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
- GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
- GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
- GitHub Check: Build Rust WASM / stable - wasm32-wasi
🔇 Additional comments (5)
lefthook.yml (5)
1-2: 确认 YAML schema 路径
请验证./node_modules/lefthook/schema.json是否能在编辑器中正确解析 schema,以便获得自动补全和校验支持。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 1-1: wrong new line character: expected \n
(new-lines)
35-44: prepare-commit-msg 钩子配置正确
交互式提交消息工具pnpm czg --hook与 skip 逻辑配置合理,可防止 Lefthook 自身递归调用。
45-49: commit-msg 钩子配置正确
已使用 Commitlint 校验提交信息并指定配置文件,符合团队规范。
50-58: post-merge 钩子确保依赖一致
在合并后检测pnpm-lock.yaml变更并提示重新安装依赖,能够有效避免版本不一致问题。
59-68: post-checkout 钩子占位符及 Shell 逻辑验证
请确认{1}、{2}、{3}占位符在实际环境中被正确替换,并保证[ {3} -eq 1 ]等判断可以在 shell 下正常执行(是否需要加引号或$前缀)。🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 68-68: no new line character at the end of file
(new-line-at-end-of-file)

这个 PR 做了什么? (简要描述所做更改)
将 husky、lint-staged 替换成 lefthook
这个 PR 是什么类型? (至少选择一个)
Summary by CodeRabbit