Skip to content

Commit 60c61fd

Browse files
committed
build: add commitlint and husky for commit message validation
- Add package.json with commitlint and husky dependencies - Configure commitlint with conventional commit rules - Set up git hook to validate commit messages before creation - Update .gitignore for Node.js files - Update CONTRIBUTING.md and README.md with setup instructions
1 parent dbc7002 commit 60c61fd

6 files changed

Lines changed: 139 additions & 7 deletions

File tree

.commitlintrc.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"extends": ["@commitlint/config-conventional"],
3+
"rules": {
4+
"type-enum": [
5+
2,
6+
"always",
7+
[
8+
"feat",
9+
"fix",
10+
"docs",
11+
"style",
12+
"refactor",
13+
"perf",
14+
"test",
15+
"build",
16+
"ci",
17+
"chore",
18+
"revert"
19+
]
20+
],
21+
"type-case": [2, "always", "lower-case"],
22+
"type-empty": [2, "never"],
23+
"subject-empty": [2, "never"],
24+
"subject-case": [0],
25+
"header-max-length": [2, "always", 100]
26+
}
27+
}

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,10 @@ cobertura.xml
8686

8787
# Generated by tests
8888
/tmp/
89+
90+
# Node.js (commitlint, semantic-release)
91+
node_modules/
92+
package-lock.json
93+
npm-debug.log*
94+
yarn-debug.log*
95+
yarn-error.log*

.husky/commit-msg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env sh
2+
. "$(dirname -- "$0")/_/husky.sh"
3+
4+
npx --no -- commitlint --edit ${1}

CONTRIBUTING.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This project adheres to a code of conduct. By participating, you are expected to
2121
### Prerequisites
2222

2323
- Rust 1.70 or higher ([Install Rust](https://rustup.rs/))
24+
- Node.js 18 or higher ([Install Node.js](https://nodejs.org/)) - for commit validation
2425
- cargo-make (optional but recommended): `cargo install --force cargo-make`
2526

2627
### Setup
@@ -35,7 +36,15 @@ This project adheres to a code of conduct. By participating, you are expected to
3536
```bash
3637
git remote add upstream https://github.com/ORIGINAL_OWNER/tmpltool.git
3738
```
38-
4. Create a new branch:
39+
4. Install Node.js dependencies (for commit validation):
40+
```bash
41+
npm install
42+
```
43+
This will:
44+
- Install commitlint and husky
45+
- Set up git hooks to validate commit messages
46+
- Prevent commits that don't follow conventional commit format
47+
5. Create a new branch:
3948
```bash
4049
git checkout -b feature/my-feature
4150
```
@@ -77,6 +86,21 @@ cargo make test-examples
7786

7887
This project uses [Conventional Commits](https://www.conventionalcommits.org/) for automated versioning and changelog generation.
7988

89+
**Important:** Commit messages are automatically validated using commitlint. Invalid commits will be rejected before they're created.
90+
91+
### Commit Validation
92+
93+
When you try to commit, a git hook will automatically check your commit message format. If it doesn't follow the conventional commit format, you'll see an error like:
94+
95+
```
96+
⧗ input: bad commit message
97+
✖ type must be one of [feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert] [type-enum]
98+
✖ found 1 problems, 0 warnings
99+
husky - commit-msg hook exited with code 1 (error)
100+
```
101+
102+
To fix this, make sure your commit message follows the format below.
103+
80104
### Commit Message Format
81105

82106
```
@@ -279,6 +303,34 @@ Releases are automated using semantic-release:
279303
- Creates GitHub release
280304
- Publishes Docker image
281305

306+
## Troubleshooting
307+
308+
### Commit Validation Not Working
309+
310+
If commit validation isn't working:
311+
312+
1. Make sure you ran `npm install` after cloning the repository
313+
2. Check that `.husky/commit-msg` exists and is executable
314+
3. Reinstall hooks: `npm run prepare`
315+
316+
### Bypassing Commit Validation (NOT Recommended)
317+
318+
In rare cases, you may need to bypass validation (e.g., fixing a broken commit history):
319+
320+
```bash
321+
git commit --no-verify -m "your message"
322+
```
323+
324+
**Warning:** Only use `--no-verify` when absolutely necessary, as it will bypass the commit validation.
325+
326+
### Testing Commit Messages
327+
328+
You can test a commit message without making a commit:
329+
330+
```bash
331+
echo "feat: add new feature" | npx commitlint
332+
```
333+
282334
## Questions?
283335

284336
If you have questions, please:

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -984,9 +984,17 @@ For detailed contribution guidelines, including commit conventions, development
984984
### Quick Start
985985

986986
1. Fork the repository
987-
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
988-
3. Make your changes
989-
4. Run tests and QA checks (`cargo make qa`)
990-
5. Commit using [conventional commits](#commit-convention)
991-
6. Push to your fork
992-
7. Open a Pull Request
987+
2. Clone your fork and install dependencies:
988+
```bash
989+
git clone https://github.com/YOUR_USERNAME/tmpltool.git
990+
cd tmpltool
991+
npm install # Installs commit validation hooks
992+
```
993+
3. Create a feature branch (`git checkout -b feature/amazing-feature`)
994+
4. Make your changes
995+
5. Run tests and QA checks (`cargo make qa`)
996+
6. Commit using [conventional commits](#commit-convention) - invalid commits will be automatically rejected
997+
7. Push to your fork
998+
8. Open a Pull Request
999+
1000+
**Note:** Commit messages are automatically validated. If your commit is rejected, make sure it follows the [conventional commit format](#commit-convention).

package.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "tmpltool",
3+
"version": "0.0.0-development",
4+
"description": "Fast and simple command-line template rendering tool using Tera templates",
5+
"private": true,
6+
"scripts": {
7+
"prepare": "husky install",
8+
"test:commit": "commitlint --from=HEAD~1"
9+
},
10+
"repository": {
11+
"type": "git",
12+
"url": "https://github.com/bordeux/tmpltool.git"
13+
},
14+
"keywords": [
15+
"template",
16+
"tera",
17+
"cli",
18+
"rust"
19+
],
20+
"author": "",
21+
"license": "MIT",
22+
"devDependencies": {
23+
"@commitlint/cli": "^18.4.3",
24+
"@commitlint/config-conventional": "^18.4.3",
25+
"husky": "^8.0.3"
26+
},
27+
"dependencies": {
28+
"@semantic-release/changelog": "^6.0.3",
29+
"@semantic-release/exec": "^6.0.3",
30+
"@semantic-release/git": "^10.0.1",
31+
"conventional-changelog-conventionalcommits": "^7.0.2",
32+
"semantic-release": "^23.0.0"
33+
}
34+
}

0 commit comments

Comments
 (0)