You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/usage.md
+84-4Lines changed: 84 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,13 @@ Create a `git-hooks.config.{ts,js,mjs,cjs,json}` file in your project root:
17
17
importtype { GitHooksConfig } from'bun-git-hooks'
18
18
19
19
const config:GitHooksConfig= {
20
-
'pre-commit': 'bun run lint && bun run test',
20
+
// Using staged-lint for efficient file-specific linting
21
+
'pre-commit': {
22
+
'staged-lint': {
23
+
'*.{js,ts}': 'bunx --bun eslint . --fix',
24
+
'*.{css,scss}': 'stylelint --fix'
25
+
}
26
+
},
21
27
'commit-msg': 'bun commitlint --edit $1',
22
28
'pre-push': 'bun run build',
23
29
'verbose': true,
@@ -33,7 +39,12 @@ You can also use JSON format in your `package.json`:
33
39
```json
34
40
{
35
41
"git-hooks": {
36
-
"pre-commit": "bun run lint && bun run test",
42
+
"pre-commit": {
43
+
"staged-lint": {
44
+
"*.{js,ts}": "bunx --bun eslint . --fix",
45
+
"*.{css,scss}": "stylelint --fix"
46
+
}
47
+
},
37
48
"commit-msg": "bun commitlint --edit $1",
38
49
"pre-push": "bun run build"
39
50
}
@@ -55,6 +66,68 @@ git-hooks remove # alias
55
66
56
67
# Enable verbose logging
57
68
git-hooks --verbose
69
+
70
+
# Run staged lint for a specific hook
71
+
git-hooks run-staged-lint pre-commit
72
+
```
73
+
74
+
## Staged Lint Usage
75
+
76
+
The `staged-lint` feature allows you to run specific commands on staged files matching certain patterns. This is more efficient than running commands on all files.
77
+
78
+
### Basic Staged Lint
79
+
80
+
```ts
81
+
const config:GitHooksConfig= {
82
+
'pre-commit': {
83
+
'staged-lint': {
84
+
// Run ESLint on JavaScript and TypeScript files
85
+
'*.{js,ts}': 'bunx --bun eslint . --fix',
86
+
87
+
// Run Stylelint on CSS and SCSS files
88
+
'*.{css,scss}': 'stylelint --fix'
89
+
}
90
+
}
91
+
}
92
+
```
93
+
94
+
### Multiple Commands
95
+
96
+
You can run multiple commands on the same file pattern:
97
+
98
+
```ts
99
+
const config:GitHooksConfig= {
100
+
'pre-commit': {
101
+
'staged-lint': {
102
+
// Run both ESLint and Prettier on TypeScript files
103
+
'*.{ts,tsx}': [
104
+
'eslint . --fix',
105
+
'prettier --write'
106
+
]
107
+
}
108
+
}
109
+
}
110
+
```
111
+
112
+
### Global Staged Lint
113
+
114
+
You can define staged lint rules globally that apply to all hooks:
0 commit comments