Skip to content

Commit ee953ee

Browse files
committed
chore: wip
1 parent 138f9ea commit ee953ee

15 files changed

+468
-151
lines changed

bin/cli.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ cli
3434

3535
if (configPath) {
3636
const config = await import(configPath)
37-
setHooksFromConfig(process.cwd(), { configFile: config, verbose: options?.verbose })
37+
setHooksFromConfig(process.cwd(), { configFile: config, verbose: options?.verbose ?? false })
3838
}
3939
else {
40-
setHooksFromConfig(process.cwd(), { verbose: options?.verbose })
40+
setHooksFromConfig(process.cwd(), { verbose: options?.verbose ?? false })
4141
}
4242

4343
log.success('Successfully set all git hooks')

bun.lock

Lines changed: 150 additions & 28 deletions
Large diffs are not rendered by default.

docs/advanced/configuration.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ git-hooks.config.json
3737
import type { GitHooksConfig } from 'bun-git-hooks'
3838

3939
const config: GitHooksConfig = {
40-
'preCommit': process.env.CI
40+
preCommit: process.env.CI
4141
? 'bun run test:ci'
4242
: {
43-
'stagedLint': {
43+
stagedLint: {
4444
'*.ts': 'eslint --fix'
4545
}
4646
}
@@ -57,16 +57,16 @@ function getConfig(): GitHooksConfig {
5757
const isCI = Boolean(process.env.CI)
5858

5959
return {
60-
'preCommit': {
61-
'stagedLint': {
60+
preCommit: {
61+
stagedLint: {
6262
'*.ts': [
6363
'eslint --fix',
6464
isProduction ? 'tsc --noEmit' : null,
6565
].filter(Boolean)
6666
}
6767
},
68-
'prePush': isCI ? 'bun run test:ci' : 'bun run test',
69-
'verbose': !isCI
68+
prePush: isCI ? 'bun run test:ci' : 'bun run test',
69+
verbose: !isCI
7070
}
7171
}
7272

@@ -81,22 +81,22 @@ export default getConfig()
8181
import { baseConfig } from './base.config'
8282

8383
export const baseConfig: GitHooksConfig = {
84-
'preCommit': 'bun run lint',
85-
'commitMsg': 'bun commitlint --edit $1'
84+
preCommit: 'bun run lint',
85+
commitMsg: 'bun commitlint --edit $1'
8686
}
8787

8888
export default {
8989
...baseConfig,
90-
'preCommit': {
91-
'stagedLint': {
90+
preCommit: {
91+
stagedLint: {
9292
'*.ts': 'eslint --fix'
9393
}
9494
}
9595
}
9696

9797
export default {
9898
...baseConfig,
99-
'prePush': [
99+
prePush: [
100100
'bun run test',
101101
'bun run build',
102102
'bun run security:check'
@@ -113,27 +113,27 @@ import type { GitHooksConfig } from 'bun-git-hooks'
113113
import { getAffectedPackages } from './scripts/monorepo'
114114

115115
const config: GitHooksConfig = {
116-
'preCommit': async () => {
116+
preCommit: async () => {
117117
const packages = await getAffectedPackages()
118118
return {
119-
'stagedLint': {
119+
stagedLint: {
120120
[`packages/{${packages.join(',')}}/src/**/*.ts`]: [
121121
'eslint --fix',
122122
'prettier --write'
123123
]
124124
}
125125
}
126126
},
127-
'prePush': 'bun run test:affected'
127+
prePush: 'bun run test:affected'
128128
}
129129
```
130130

131131
### Custom Hook Scripts
132132

133133
```ts
134134
const config: GitHooksConfig = {
135-
'preCommit': {
136-
'stagedLint': {
135+
preCommit: {
136+
stagedLint: {
137137
// Custom script for specific files
138138
'*.graphql': async (files) => {
139139
const schema = await loadSchema()
@@ -155,8 +155,8 @@ const config: GitHooksConfig = {
155155

156156
```ts
157157
const config: GitHooksConfig = {
158-
'preCommit': {
159-
'stagedLint': {
158+
preCommit: {
159+
stagedLint: {
160160
'*.ts': async (files) => {
161161
// Development: Fast checks
162162
if (process.env.NODE_ENV === 'development') {

docs/api-reference.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ The main configuration type for the package. It defines the structure of your gi
1212
type GitHooksConfig = {
1313
// Git hook configurations
1414
[hookName in GitHook]?: string | {
15-
'stagedLint'?: StagedLintConfig
15+
stagedLint?: StagedLintConfig
1616
}
1717
} & {
1818
// Global options
19-
'preserveUnused'?: boolean | GitHook[]
20-
'verbose'?: boolean
21-
'stagedLint'?: StagedLintConfig
19+
preserveUnused?: boolean | GitHook[]
20+
verbose?: boolean
21+
stagedLint?: StagedLintConfig
2222
}
2323
```
2424
@@ -127,38 +127,38 @@ Or in `package.json`:
127127
128128
```ts
129129
const config: GitHooksConfig = {
130-
'preCommit': 'bun run lint',
131-
'commitMsg': 'bun commitlint --edit $1',
132-
'prePush': 'bun run test'
130+
preCommit: 'bun run lint',
131+
commitMsg: 'bun commitlint --edit $1',
132+
prePush: 'bun run test'
133133
}
134134
```
135135

136136
### Advanced Configuration with Staged Linting
137137

138138
```ts
139139
const config: GitHooksConfig = {
140-
'preCommit': {
141-
'stagedLint': {
140+
preCommit: {
141+
stagedLint: {
142142
'*.{js,ts}': ['eslint --fix', 'prettier --write'],
143143
'*.{css,scss}': 'stylelint --fix'
144144
}
145145
},
146-
'verbose': true,
147-
'preserveUnused': ['postCheckout']
146+
verbose: true,
147+
preserveUnused: ['postCheckout']
148148
}
149149
```
150150

151151
### Dynamic Configuration
152152

153153
```ts
154154
const config: GitHooksConfig = {
155-
'preCommit': process.env.CI
155+
preCommit: process.env.CI
156156
? 'bun run test:ci'
157157
: {
158-
'stagedLint': {
158+
stagedLint: {
159159
'*.ts': 'eslint --fix'
160160
}
161161
},
162-
'verbose': !process.env.CI
162+
verbose: !process.env.CI
163163
}
164164
```

docs/config.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ import type { GitHooksConfig } from 'bun-git-hooks'
3333

3434
const config: GitHooksConfig = {
3535
// Note: stagedLint is only available in preCommit hook
36-
'preCommit': {
37-
'stagedLint': {
36+
preCommit: {
37+
stagedLint: {
3838
'*.{js,ts}': 'bunx --bun eslint . --fix',
3939
'*.{css,scss}': 'stylelint --fix'
4040
}
4141
},
42-
'commitMsg': 'bun commitlint --edit $1',
43-
'prePush': 'bun run build',
42+
commitMsg: 'bun commitlint --edit $1',
43+
prePush: 'bun run build',
4444

4545
// Optional settings
46-
'verbose': true, // Enable verbose logging
47-
'preserveUnused': false, // Remove unused hooks (default)
46+
verbose: true, // Enable verbose logging
47+
preserveUnused: false, // Remove unused hooks (default)
4848
}
4949

5050
export default config
@@ -76,11 +76,11 @@ Any valid git hook can be configured with either a command string or a staged-li
7676
```ts
7777
const config: GitHooksConfig = {
7878
// Simple command
79-
'preCommit': 'bun run lint',
79+
preCommit: 'bun run lint',
8080

8181
// Staged lint configuration (preCommit only)
82-
'preCommit': {
83-
'stagedLint': {
82+
preCommit: {
83+
stagedLint: {
8484
'*.{js,ts}': 'bunx --bun eslint . --fix',
8585
'*.{css,scss}': 'stylelint --fix'
8686
}
@@ -94,8 +94,8 @@ The `stagedLint` feature is only available in the preCommit hook. It allows you
9494

9595
```ts
9696
const config: GitHooksConfig = {
97-
'preCommit': {
98-
'stagedLint': {
97+
preCommit: {
98+
stagedLint: {
9999
// Run ESLint on JavaScript and TypeScript files
100100
'*.{js,ts}': 'bunx --bun eslint . --fix',
101101

@@ -131,21 +131,21 @@ Some hooks receive arguments from Git that you can use in your commands:
131131
```ts
132132
const config: GitHooksConfig = {
133133
// $1 is the commit message file path
134-
'commitMsg': 'bun commitlint --edit $1',
134+
commitMsg: 'bun commitlint --edit $1',
135135

136136
// $1 is the previous HEAD, $2 is the new HEAD
137-
'postCheckout': 'bun run update-deps $1 $2',
137+
postCheckout: 'bun run update-deps $1 $2',
138138
}
139139
```
140140

141141
### Preserving Specific Hooks
142142

143143
```ts
144144
const config: GitHooksConfig = {
145-
'preCommit': 'bun run lint',
145+
preCommit: 'bun run lint',
146146

147147
// Keep specific hooks when cleaning up
148-
'preserveUnused': ['postMerge', 'postCheckout'],
148+
preserveUnused: ['postMerge', 'postCheckout'],
149149
}
150150
```
151151

@@ -154,10 +154,10 @@ const config: GitHooksConfig = {
154154
```ts
155155
const config: GitHooksConfig = {
156156
// Multiple commands with &&
157-
'preCommit': 'bun run lint && bun run test && bun run build',
157+
preCommit: 'bun run lint && bun run test && bun run build',
158158

159159
// Or using array join for better readability
160-
'prePush': [
160+
prePush: [
161161
'bun run build',
162162
'bun run test:e2e',
163163
'bun run deploy'

docs/features/hook-management.md

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ All standard Git hooks are supported:
2121

2222
```ts
2323
const config: GitHooksConfig = {
24-
'preCommit': 'bun run lint',
25-
'commitMsg': 'bun commitlint --edit $1',
26-
'prePush': 'bun run test'
24+
preCommit: 'bun run lint',
25+
commitMsg: 'bun commitlint --edit $1',
26+
prePush: 'bun run test'
2727
}
2828
```
2929

@@ -32,20 +32,20 @@ const config: GitHooksConfig = {
3232
```ts
3333
const config: GitHooksConfig = {
3434
// Hook with staged linting
35-
'preCommit': {
36-
'stagedLint': {
35+
preCommit: {
36+
stagedLint: {
3737
'*.ts': 'eslint --fix'
3838
}
3939
},
4040

4141
// Simple command hook
42-
'commitMsg': 'bun commitlint --edit $1',
42+
commitMsg: 'bun commitlint --edit $1',
4343

4444
// Preserve specific unused hooks
45-
'preserveUnused': ['postCheckout', 'postMerge'],
45+
preserveUnused: ['postCheckout', 'postMerge'],
4646

4747
// Enable verbose logging
48-
'verbose': true
48+
verbose: true
4949
}
5050
```
5151

@@ -110,24 +110,24 @@ SKIP_INSTALL_GIT_HOOKS=1 bun install
110110
```ts
111111
const config: GitHooksConfig = {
112112
// Quality checks before commit
113-
'preCommit': {
114-
'stagedLint': {
113+
preCommit: {
114+
stagedLint: {
115115
'*.{js,ts}': 'eslint --fix',
116116
'*.{css,scss}': 'stylelint --fix'
117117
}
118118
},
119119

120120
// Validate commit messages
121-
'commitMsg': 'bun commitlint --edit $1',
121+
commitMsg: 'bun commitlint --edit $1',
122122

123123
// Run tests before push
124-
'prePush': 'bun run test',
124+
prePush: 'bun run test',
125125

126126
// Update dependencies after branch switch
127-
'postCheckout': 'bun install',
127+
postCheckout: 'bun install',
128128

129129
// Verbose output for debugging
130-
'verbose': true
130+
verbose: true
131131
}
132132
```
133133

@@ -136,16 +136,16 @@ const config: GitHooksConfig = {
136136
```ts
137137
const config: GitHooksConfig = {
138138
// Comprehensive checks before commit
139-
'preCommit': [
139+
preCommit: [
140140
'bun run lint',
141141
'bun run test:unit',
142142
'bun run build'
143143
],
144144

145145
// Prevent direct commits to main
146-
'prePush': 'bash scripts/prevent-main-push.sh',
146+
prePush: 'bash scripts/prevent-main-push.sh',
147147

148148
// Run security checks
149-
'preCommit': 'bun run security:audit'
149+
preCommit: 'bun run security:audit'
150150
}
151151
```

docs/features/staged-linting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ The `autoRestage` feature automatically re-stages files that are modified by lin
151151
"stagedLint": {
152152
"*.{js,ts}": "eslint --fix"
153153
},
154-
"autoRestage": true // Default: true
154+
"autoRestage": true // Default: true
155155
}
156156
}
157157
```

0 commit comments

Comments
 (0)