Skip to content

Commit 18a6130

Browse files
committed
chore: setup commitlint with pnpm and add documentation
1 parent 537805e commit 18a6130

6 files changed

Lines changed: 720 additions & 1054 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ vendor/
2323
#JsonFile
2424
drive_api_key.json
2525

26-
2726
node_modules/

.husky/commit-msg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
npx --no -- commitlint --edit $1
1+
pnpm dlx commitlint --edit $1

commitlint.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Install
2+
3+
```console
4+
pnpm add -D @commitlint/cli @commitlint/config-conventional
5+
```
6+
7+
# Configuration
8+
Configure commitlint to use conventional config
9+
```console
10+
module.exports = { extends: ['@commitlint/config-conventional'] };
11+
```
12+
13+
# Add hook
14+
To use commitlint you need to setup commit-msg hook
15+
16+
```console
17+
pnpm add --save-dev husky
18+
# husky@v9
19+
pnpm husky init
20+
# husky@v8 or lower
21+
pnpm husky install
22+
# Add commit message linting to commit-msg hook
23+
echo "pnpm dlx commitlint --edit \$1" > .husky/commit-msg
24+
```
25+
26+
# Test simple usage
27+
For a first simple usage test of commitlint you can do the following:
28+
```console
29+
pnpm commitlint --from HEAD~1 --to HEAD --verbose
30+
```
31+
This will check your last commit and return an error if invalid or a positive output if valid.
32+
# Test the hook
33+
You can test the hook by simply committing. You should see something like this if everything works
34+
## Invalid commit
35+
```console
36+
git commit -m "foo: this will fail"
37+
# husky > commit-msg
38+
No staged files match any of provided globs.
39+
⧗ --- input ---
40+
foo: this will fail
41+
✖ type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]
42+
43+
✖ found 1 problems, 0 warnings
44+
ⓘ Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint
45+
46+
husky - commit-msg script failed (code 1)
47+
```
48+
## Valid commit
49+
```console
50+
git commit -m "chore: lint on commitmsg"
51+
# husky > pre-commit
52+
No staged files match any of provided globs.
53+
# husky > commit-msg
54+
```
55+
# References
56+
57+
- Commitlint:
58+
https://commitlint.js.org/guides/local-setup.html
59+
- Conventional Commits:
60+
https://www.conventionalcommits.org/en/v1.0.0/

0 commit comments

Comments
 (0)