Skip to content

Commit 322f49c

Browse files
authored
Merge pull request #70 from drivecore/feature/add-precommit-hooks
Add pre-commit hooks for lint and format commands
2 parents 7838cea + 1fe03f3 commit 322f49c

File tree

4 files changed

+316
-3
lines changed

4 files changed

+316
-3
lines changed

.husky/pre-commit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pnpm lint-staged

CONTRIBUTING.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,22 @@ This project and everyone participating in it is governed by our Code of Conduct
7979

8080
5. Push to your fork and create a Pull Request
8181

82+
6. Pre-commit Hooks:
83+
84+
We use [husky](https://typicode.github.io/husky/) and [lint-staged](https://github.com/okonet/lint-staged) to automatically run linting and formatting on staged files before each commit. This helps maintain code quality and consistency.
85+
86+
The pre-commit hooks are configured to run:
87+
- `pnpm lint`: Lints the staged files using ESLint
88+
- `pnpm format`: Formats the staged files using Prettier
89+
90+
If either of these commands fails due to linting errors or formatting issues, the commit will be aborted. Please fix the reported issues and try committing again.
91+
92+
You can also run the lint and format commands manually at any time:
93+
```bash
94+
pnpm lint # Lint all files
95+
pnpm format # Format all files
96+
```
97+
8298
## Package-Specific Guidelines
8399

84100
### Agent Development

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,14 @@
2222
"changeset": "changeset",
2323
"version": "changeset version",
2424
"release": "changeset publish",
25-
"cli": "cd packages/cli && node --no-deprecation bin/cli.js"
25+
"cli": "cd packages/cli && node --no-deprecation bin/cli.js",
26+
"prepare": "husky"
27+
},
28+
"lint-staged": {
29+
"*.{js,jsx,ts,tsx}": [
30+
"pnpm lint",
31+
"pnpm format"
32+
]
2633
},
2734
"dependencies": {
2835
"rimraf": "^6.0.1"
@@ -39,6 +46,8 @@
3946
"eslint-plugin-prettier": "^5",
4047
"eslint-plugin-promise": "^7.2.1",
4148
"eslint-plugin-unused-imports": "^4.1.4",
49+
"husky": "^9.1.7",
50+
"lint-staged": "^15.4.3",
4251
"prettier": "^3.5.1",
4352
"typescript-eslint": "^8.23.0"
4453
},

0 commit comments

Comments
 (0)