Skip to content

Commit 13565c6

Browse files
committed
feat(project): migrate from husky and lint-staged to lefthook
1 parent 17a18fc commit 13565c6

File tree

17 files changed

+307
-116
lines changed

17 files changed

+307
-116
lines changed

.husky/commit-msg

Lines changed: 0 additions & 6 deletions
This file was deleted.

.husky/post-merge

Lines changed: 0 additions & 3 deletions
This file was deleted.

.husky/pre-commit

Lines changed: 0 additions & 7 deletions
This file was deleted.

.lintstagedrc.mjs

Lines changed: 0 additions & 20 deletions
This file was deleted.

.npmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
registry = "https://registry.npmmirror.com"
2-
public-hoist-pattern[]=husky
2+
public-hoist-pattern[]=lefthook
33
public-hoist-pattern[]=eslint
44
public-hoist-pattern[]=prettier
55
public-hoist-pattern[]=prettier-plugin-tailwindcss

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@
219219
"*.env": "$(capture).env.*",
220220
"README.md": "README*,CHANGELOG*,LICENSE,CNAME",
221221
"package.json": "pnpm-lock.yaml,pnpm-workspace.yaml,.gitattributes,.gitignore,.gitpod.yml,.npmrc,.browserslistrc,.node-version,.git*,.tazerc.json",
222-
"eslint.config.mjs": ".eslintignore,.prettierignore,.stylelintignore,.commitlintrc.*,.prettierrc.*,stylelint.config.*,.lintstagedrc.mjs,cspell.json",
222+
"eslint.config.mjs": ".eslintignore,.prettierignore,.stylelintignore,.commitlintrc.*,.prettierrc.*,stylelint.config.*,.lintstagedrc.mjs,cspell.json,lefthook.yml",
223223
"tailwind.config.mjs": "postcss.*"
224224
},
225225
"commentTranslate.hover.enabled": false,

docs/src/en/guide/essentials/development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ The execution command is: `pnpm run [script]` or `npm run [script]`.
9898
"postinstall": "pnpm -r run stub --if-present",
9999
// Only allow using pnpm
100100
"preinstall": "npx only-allow pnpm",
101-
// Install husky
102-
"prepare": "is-ci || husky",
101+
// Install lefthook
102+
"prepare": "is-ci || lefthook install",
103103
// Preview the application
104104
"preview": "turbo-run preview",
105105
// Package specification check

docs/src/en/guide/other/faq.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ If you encounter a problem, you can start looking from the following aspects:
1818

1919
## Dependency Issues
2020

21-
In a `Monorepo` project, it is necessary to develop the habit of executing `pnpm install` every time you `git pull` the code, as new dependency packages are often added. The project has already configured automatic execution of `pnpm install` in `.husky/git-merge`, but sometimes there might be issues. If it does not execute automatically, it is recommended to execute it manually once.
21+
In a `Monorepo` project, it's important to get into the habit of running `pnpm install` after every `git pull` because new dependencies are often added. The project has configured automatic execution of `pnpm install` in `lefthook.yml`, but sometimes there might be issues. If it does not execute automatically, it is recommended to execute it manually once.
2222

2323
## About Cache Update Issues
2424

docs/src/en/guide/project/standard.md

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ The project integrates the following code verification tools:
3333
- [Prettier](https://prettier.io/) for code formatting
3434
- [Commitlint](https://commitlint.js.org/) for checking the standard of git commit messages
3535
- [Publint](https://publint.dev/) for checking the standard of npm packages
36-
- [Lint Staged](https://github.com/lint-staged/lint-staged) for running code verification before git commits
3736
- [Cspell](https://cspell.org/) for checking spelling errors
37+
- [lefthook](https://github.com/evilmartians/lefthook) for managing Git hooks, automatically running code checks and formatting before commits
3838

3939
## ESLint
4040

@@ -148,18 +148,66 @@ The cspell configuration file is `cspell.json`, which can be modified according
148148

149149
Git hooks are generally combined with various lints to check code style during git commits. If the check fails, the commit will not proceed. Developers need to modify and resubmit.
150150

151-
### husky
151+
### lefthook
152152

153-
One issue is that the check will verify all code, but we only want to check the code we are committing. This is where husky comes in.
153+
One issue is that the check will verify all code, but we only want to check the code we are committing. This is where lefthook comes in.
154154

155-
The most effective solution is to perform Lint checks locally before committing. A common practice is to use husky or pre-commit to perform a Lint check before local submission.
155+
The most effective solution is to perform Lint checks locally before committing. A common practice is to use lefthook to perform a Lint check before local submission.
156156

157-
The project defines corresponding hooks inside `.husky`.
157+
The project defines corresponding hooks inside `lefthook.yml`:
158158

159-
#### How to Disable Husky
159+
- `pre-commit`: Runs before commit, used for code formatting and checking
160160

161-
If you want to disable Husky, simply delete the .husky directory.
161+
- `code-workspace`: Updates VSCode workspace configuration
162+
- `lint-md`: Formats Markdown files
163+
- `lint-vue`: Formats and checks Vue files
164+
- `lint-js`: Formats and checks JavaScript/TypeScript files
165+
- `lint-style`: Formats and checks style files
166+
- `lint-package`: Formats package.json
167+
- `lint-json`: Formats other JSON files
162168

163-
### lint-staged
169+
- `post-merge`: Runs after merge, used for automatic dependency installation
164170

165-
Used for automatically fixing style issues of committed files. Its configuration file is `.lintstagedrc.mjs`, which can be modified according to project needs.
171+
- `install`: Runs `pnpm install` to install new dependencies
172+
173+
- `commit-msg`: Runs during commit, used for checking commit message format
174+
- `commitlint`: Uses commitlint to check commit messages
175+
176+
#### How to Disable lefthook
177+
178+
If you want to disable lefthook, there are two ways:
179+
180+
::: code-group
181+
182+
```bash [Temporary disable]
183+
git commit -m 'feat: add home page' --no-verify
184+
```
185+
186+
```bash [Permanent disable]
187+
# Simply delete the lefthook.yml file
188+
rm lefthook.yml
189+
```
190+
191+
:::
192+
193+
#### How to Modify lefthook Configuration
194+
195+
If you want to modify lefthook's configuration, you can edit the `lefthook.yml` file. For example:
196+
197+
```yaml
198+
pre-commit:
199+
parallel: true # Execute tasks in parallel
200+
jobs:
201+
- name: lint-js
202+
run: pnpm prettier --cache --ignore-unknown --write {staged_files}
203+
glob: '*.{js,jsx,ts,tsx}'
204+
```
205+
206+
Where:
207+
208+
- `parallel`: Whether to execute tasks in parallel
209+
- `jobs`: Defines the list of tasks to execute
210+
- `name`: Task name
211+
- `run`: Command to execute
212+
- `glob`: File pattern to match
213+
- `{staged_files}`: Represents the list of staged files

docs/src/guide/essentials/development.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ npm 脚本是项目常见的配置,用于执行一些常见的任务,比如
9898
"postinstall": "pnpm -r run stub --if-present",
9999
// 只允许使用pnpm
100100
"preinstall": "npx only-allow pnpm",
101-
// husky的安装
102-
"prepare": "is-ci || husky",
101+
// lefthook的安装
102+
"prepare": "is-ci || lefthook install",
103103
// 预览应用
104104
"preview": "turbo-run preview",
105105
// 包规范检查

0 commit comments

Comments
 (0)