Skip to content

Commit 37e02b2

Browse files
🤖 Merge PR DefinitelyTyped#68187 Set up optional pre-commit format hook with husky and lint-staged by @tpluscode
* style: optional formatting on pre-commit hook * explicit lint-staged config (re lint-staged/lint-staged#1383) * docs: mention checking out hooks, + tweak hook command * chore: remove config (moved to .lintstagedrc.jsn) * refactor: lint-staged everything * Update README.md Co-authored-by: Jake Bailey <[email protected]> * docs: move git hook section --------- Co-authored-by: Jake Bailey <[email protected]>
1 parent f002821 commit 37e02b2

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

‎.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
pnpm lint-staged --config .lintstagedrc.json --allow-empty

‎.lintstagedrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "*": "pnpm dprint fmt --allow-no-files" }

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,8 @@ Then they are wrong and we've not noticed yet. You can help by submitting a pull
488488
Yes, using [dprint](https://dprint.dev).
489489
We recommend using a [dprint extension for your editor](https://dprint.dev/install/#editor-extensions).
490490
491+
Alternatively, you can enable a git hook which will format your code automatically. Run `pnpm run setup-hooks`. Then, when you commit, `dprint fmt` command will be executed on changed files. If you take advantage of [partial clone](#partial-clone), make sure to call `git sparse-checkout add .husky` to check out the git hooks before running the `setup-hooks` script.
492+
491493
Pull requests do not require correct formatting to be merged.
492494
Any unformatted code will be automatically reformatted after being merged.
493495

‎package.json

+5-8
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"clean-node-modules": "node scripts/clean-node-modules.js",
2626
"test": "node --enable-source-maps node_modules/@definitelytyped/dtslint/ types",
2727
"lint": "node --enable-source-maps node_modules/@definitelytyped/dtslint/ types",
28-
"prettier": "prettier"
28+
"prettier": "prettier",
29+
"setup-hooks": "husky install"
2930
},
3031
"devDependencies": {
3132
"@definitelytyped/definitions-parser": "latest",
@@ -39,16 +40,12 @@
3940
"danger": "^11.2.3",
4041
"dprint": "^0.45.0",
4142
"eslint-plugin-jsdoc": "^44.2.7",
43+
"husky": "^8.0.3",
44+
"lint-staged": "^15.2.0",
4245
"remark-cli": "^11.0.0",
4346
"remark-gfm": "^3.0.0",
4447
"remark-validate-links": "^12.0.0",
4548
"typescript": "next"
4649
},
47-
"type": "module",
48-
"husky": {
49-
"hooks": {
50-
"_comment": "This will remove husky from when we started migrating to use prettier",
51-
"pre-commit": "npm uninstall husky"
52-
}
53-
}
50+
"type": "module"
5451
}

0 commit comments

Comments
 (0)