Skip to content

Commit e78018c

Browse files
authored
Merge pull request #7 from forumone/husky-setup
Husky setup
2 parents 8faf1f7 + 9b1cb03 commit e78018c

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

.github/workflows/checks.yml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,6 @@ name: Code checks
33
on: [pull_request]
44

55
jobs:
6-
prettier:
7-
runs-on: ubuntu-latest
8-
9-
strategy:
10-
matrix:
11-
node-version: [16.x]
12-
13-
steps:
14-
- name: Checkout commit
15-
uses: actions/checkout@v2
16-
17-
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v2
19-
with:
20-
node-version: ${{ matrix.node-version }}
21-
22-
- name: Cache NPM
23-
uses: actions/cache@v2
24-
with:
25-
path: ~/.npm
26-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
27-
restore-keys: |
28-
${{ runner.os }}-node-
29-
30-
- name: Install packages
31-
run: npm ci
32-
33-
- name: Run Prettier
34-
run: npm run prettier
35-
366
lint:
377
runs-on: ubuntu-latest
388

.husky/pre-commit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
npm test

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,18 @@ npm run tsc
9292

9393
Runs `tsc --noEmit`, which will compile the TypeScript code without emitting files. This acts as a TS error check in your CLI. This is useful to catch TS errors that you might miss during development. For more information, see the [TypeScript Compiler (tsc) documentation](https://www.typescriptlang.org/docs/handbook/compiler-options.html).
9494

95+
## Husky
96+
97+
This project uses [Husky](https://typicode.github.io/husky/#/) to check code on git commits. By default, it is setup to use the `npm test` script which runs `lint` and `tsc` (TypeScript) checks against the codebase. This check occurs on `git commit` attempts. This helps developers catch errors _before_ pushing branches and creating PRs, quickening the overall dev worklow.
98+
99+
To bypass this check, you can use the `--no-verify` flag with your commit:
100+
101+
```bash
102+
git commit -m "This will not get checked by Husky." --no-verify
103+
```
104+
105+
Note that bypassing the Husky check is frowned upon.
106+
95107
## Notes
96108

97109
* Code for the app is currently configured to go into the `pages` directory (for [Next.js pages](https://nextjs.org/docs/basic-features/pages)) and `source` for theming, components, providers, helpers, etc.

package-lock.json

Lines changed: 24 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
"lint": "next lint",
1111
"prettier": "prettier --check pages/ source/",
1212
"prettier:write": "prettier --write pages/ source/",
13-
"tsc": "tsc --noEmit"
13+
"tsc": "tsc --noEmit",
14+
"test": "npm run lint && npm run tsc",
15+
"prepare": "husky install"
1416
},
1517
"dependencies": {
1618
"@emotion/css": "^11.9.0",
@@ -32,6 +34,7 @@
3234
"eslint-config-next": "^12.1.5",
3335
"eslint-config-prettier": "^8.5.0",
3436
"eslint-plugin-prettier": "^4.0.0",
37+
"husky": "^7.0.4",
3538
"prettier": "^2.6.2",
3639
"prettier-plugin-organize-imports": "^2.3.4",
3740
"typescript": "^4.6.3"

0 commit comments

Comments
 (0)