CommitLint.Net
0.5.3
See the version list below for details.
dotnet tool install --global CommitLint.Net --version 0.5.3
dotnet new tool-manifest # if you are setting up this repo dotnet tool install --local CommitLint.Net --version 0.5.3
#tool dotnet:?package=CommitLint.Net&version=0.5.3
nuke :add-package CommitLint.Net --version 0.5.3
What is CommitLint.Net?
It is a dotnet tool for validating commit messages according to Conventional Commits specification. It can be used in git hook, for example with Husky.NET. It is also included in xpd project.
How to use
Install
dotnet new tool-manifest # if this is your first local dotnet tool in this project
dotnet tool install CommitLint.Net
Configure Husky.NET
Install & configure Husky.NET (there is slight difference between platform in parsing $1 argument):
MacOS
dotnet tool install Husky
dotnet husky install
dotnet husky add commit-msg -c "dotnet husky run --group commit-msg --args \"\$1\""
Windows
dotnet tool install Husky
dotnet husky install
dotnet husky add commit-msg -c 'dotnet husky run --group commit-msg --args """$1"""'
In the end, entry in commit-msg
file that will be created by dotnet husky add
should be:
dotnet husky run --group commit-msg --args "$1"
Then in .husky/task-runner.json
add task to run linter:
{
"$schema": "https://alirezanet.github.io/Husky.Net/schema.json",
"tasks": [
{
"name": "commit-message-linter",
"group": "commit-msg",
"command": "dotnet",
"args": [
"commit-lint",
"--commit-file",
"${args}"
]
}
]
}
Custom config
CommitLint.Net uses default configuration which is the following:
{
"config": {
"max-subject-length": {
"enabled": true,
"value": 90
},
"conventional-commit": {
"enabled": true,
"types": [ "feat", "fix", "refactor", "build", "chore", "style", "test", "docs", "perf", "revert" ]
}
}
}
If you want to change it, create json file, e.g. commit-message-config.json
with above content and modify options as needed. Options listed above are all currently supported options.
If you're using Husky, then you'll also need to add this custom config to task-runner.json
with --commit-message-config-file
option:
{
"name": "commit-message-linter",
"group": "commit-msg",
"command": "dotnet",
"args": [
"commit-lint",
"--commit-file",
"${args}",
"--commit-message-config-file",
"path/to/commit-message-config.json"
]
}
path/to/commit-message-config.json
is relative to root of your repo.
Direct usage
If you'd like to use it directly, without Husky:
dotnet commit-lint --commit-file "path/to/commit-message.txt" --commit-message-config-file "path/to/commit-message-config.json"
Current Rules
- Max subject length check
- Scope format check
- Type format check + if it is on allowed list
- Description not empty check
- Blank line before body check
- Body not empty check
- Blank line before footers check
- Optional "!" character after type/scope for breaking change check
- Breaking change token in footer format check
- Footers content not empty check
Rules 2 - 10 are from Conventional Commits specification. Rule 1 is an additional one.
Rule 1 can be disabled in config and rules 2 - 10 can be disabled in config as well, but all together, not one by one.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
This package has no dependencies.