taro icon indicating copy to clipboard operation
taro copied to clipboard

chore: add lefthook

Open ianzone opened this issue 6 months ago • 6 comments

这个 PR 做了什么? (简要描述所做更改) 将 husky、lint-staged 替换成 lefthook

这个 PR 是什么类型? (至少选择一个)

  • [x] 构建优化 (Chore)

Summary by CodeRabbit

  • Chores
    • 用 Lefthook 替换了 Husky 和 lint-staged 作为 Git 钩子管理工具。
    • 更新了依赖,移除了 Husky 和 lint-staged,新增 Lefthook 和 czg。
    • 新增 Lefthook 配置,自动执行代码格式化、静态检查和提交信息校验等操作。
    • 优化依赖变更检测,合并或检出后如有依赖变更会提示重新安装依赖。
    • 新增提交脚本,简化提交流程。

ianzone avatar Jun 15 '25 19:06 ianzone

## 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: 完成 commit

Poem

🐇
换装 Lefthook 新风来,
钩子流程更自在。
格式校验并肩跑,
依赖同步不落单。
兔子挥爪乐开怀,
代码之路更畅快!


<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 0e8a6c22c4cdbccd7e0b61e2dc5b3b2e03a15b09 and 14a454a3bd630db8494fd55a0dfeebb38bf8aae9.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `pnpm-lock.yaml` is excluded by `!**/pnpm-lock.yaml`

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `package.json` (4 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* package.json

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (7)</summary>

* GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-musl
* GitHub Check: Build Rust Binding / stable - x86_64-apple-darwin
* GitHub Check: Build Rust Binding / stable - aarch64-apple-darwin
* GitHub Check: Build Rust Binding / stable - x86_64-unknown-linux-gnu
* GitHub Check: Build Rust Binding / stable - x86_64-pc-windows-msvc
* GitHub Check: Build Rust WASM / stable - wasm32-wasi
* GitHub Check: Testing on Rust

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIGWHx/LjRaekiAM1x4/ABraMgAdzRkBwFmdRp6OTDYD2xEShRMAC98cnRkW0gMRwEGgEYAdgAOABYB/ixMjwA5SgkAKQBlAHpcZ3w/Em58RHUE2Q0YGshmbSw4zFIUDFwKRWwGKPhJhA67VCnN7i80R7Yb/hpaoeEgADyQ4gwRDC+HwXmQsDq2XkmFSz1wYEQa1I9Hy6lgkHSmVh2UOcFQ2G4tGoHlQDBpRAS8CaUSK6EgAmw8C89Hw3HEZSa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SoYNIRy4KxSpQMCEgQYSsSSgQNINikYDwLhMi4yoYNATihgWKhgEYBgWgRyqqgYEgBymSkgeczyrKsCAQec+qsCNAPoLK/SgKsivoEYNAEYSSoatq2gTi1S6q0YXK5yySyStADyuuVQMCIYbK4qniti7SnSqAVJCi2gKimi/sQcWgOkwhfQIAA= -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

<details open="true">
<summary>🧪 Generate Unit Tests</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Create PR with Unit Tests
- [ ] <!-- {"checkboxId": "07f1e7d6-8a8e-4e23-9900-8731c2c87f58", "radioGroupId": "utg-output-choice-group-unknown_comment_id"} -->   Post Copyable Unit Tests in Comment

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=NervJS/taro&utm_content=17847):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai auto-generate unit tests` to generate unit tests for this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

coderabbitai[bot] avatar Jun 15 '25 19:06 coderabbitai[bot]

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 55.90%. Comparing base (d93fa03) to head (14a454a). :warning: Report is 34 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           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     
Flag Coverage Δ
taro-cli 72.42% <ø> (ø)
taro-runtime 59.87% <ø> (ø)
taro-web 53.19% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more. see 45 files with indirect coverage changes

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 15 '25 19:06 codecov[bot]

做这个改动的初衷是什么?如不是必须的,或者仅仅是个人倾向,建议先不要动。

yoyo837 avatar Jun 16 '25 01:06 yoyo837

做这个改动的初衷是什么?如不是必须的,或者仅仅是个人倾向,建议先不要动。

  1. lefthook 可替代 husky 和 lint-staged,减少依赖
  2. 它可以将所有 git 钩子都写在一个配置文件里,减少文件
  3. 的 yml 配置文件的风格类似 CI 配置,结构清晰,可读性更好

ianzone avatar Jun 16 '25 02:06 ianzone

运行效果 image

ianzone avatar Jun 16 '25 03:06 ianzone

@Single-Dancer 大佬给个意见?

ianzone avatar Jun 26 '25 13:06 ianzone