Skip to content

Commit 06c7751

Browse files
authored
chore: add husky commit and push hooks (#588)
1 parent fb2f38e commit 06c7751

7 files changed

Lines changed: 594 additions & 7 deletions

File tree

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run precommit

.husky/pre-push

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
npm run prepush

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ Useful scripts:
6969

7070
- `npm run lint` / `npm run format`
7171
- `npm run test` (unit) / `npm run test:e2e` (playwright)
72+
- `npm run precommit` to run the same checks as the Git pre-commit hook
73+
- `npm run prepush` to run the same checks as the Git pre-push hook
74+
75+
Git hooks are installed automatically via `npm install`/`npm run setup` with
76+
Husky:
77+
78+
- `pre-commit`: formats staged files with Prettier via `lint-staged`, then runs
79+
linting, type checking, and builds the workspace
80+
- `pre-push`: runs the test suite before allowing a push
7281

7382
## Links
7483

docs/development.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,40 @@ npm run dev
3434
Make sure that if the path includes spaces, you wrap the path in quotes as shown
3535
above (note the use of single quotes wrapping the double quotes!).
3636

37+
## Git hooks
38+
39+
This repo installs Git hooks automatically via Husky when you run `npm install`
40+
because the root `prepare` script runs `husky`.
41+
42+
### Pre-commit
43+
44+
Every commit runs:
45+
46+
- `npm run format:staged` to format only staged files with Prettier via
47+
`lint-staged`
48+
- `npm run lint`
49+
- `npm run typecheck`
50+
- `npm run build`
51+
52+
If a staged file is reformatted, lint-staged updates the staged copy before the
53+
rest of the checks continue.
54+
55+
### Pre-push
56+
57+
Every push runs:
58+
59+
- `npm run test`
60+
61+
### Running the same checks manually
62+
63+
```sh
64+
npm run precommit
65+
npm run prepush
66+
```
67+
68+
If you need to bypass hooks for an emergency local workflow, use Git's
69+
`--no-verify` flag intentionally and sparingly.
70+
3771
## CI Workflows
3872

3973
This repository has two main CI workflows that run on pushes to `main`:

0 commit comments

Comments
 (0)