@rajzik/conventional-commit-lint-config
v2.1.3
Published
Conventional commit lint config for personal projects
Maintainers
Readme
@rajzik/conventional-commit-lint-config
Commitlint configuration for the rajzik conventional changelog preset. Enforces conventional commit message format in your repository.
Installation
npm install --save-dev @commitlint/cli @rajzik/conventional-commit-lint-config
pnpm install --save-dev @commitlint/cli @rajzik/conventional-commit-lint-config
yarn add --dev @commitlint/cli @rajzik/conventional-commit-lint-configUsage
Configuration
Create a commitlint.config.cjs (CommonJS) or commitlint.config.mjs (ESM)
file:
CommonJS (commitlint.config.cjs):
module.exports = {
extends: ['@rajzik/conventional-commit-lint-config'],
};ESM (commitlint.config.mjs):
export default {
extends: ['@rajzik/conventional-commit-lint-config'],
};Integration with Git Hooks
Using Husky
npm install --save-dev husky
npx husky initAdd to .husky/commit-msg:
npx --no -- commitlint --edit $1Using lint-staged
{
"lint-staged": {
"*.{ts,tsx,js,jsx}": ["commitlint --edit"]
}
}CLI Usage
# Check a commit message
echo "fix: Fix bug" | npx commitlint
# Check from stdin
npx commitlint --edit
# Check last commit
git log -1 --pretty=%B | npx commitlintAPI Reference
Default Export
The default export is a commitlint configuration object:
{
rules: {
'body-max-length': [0],
'scope-case': [0, 'never', 'start-case'],
'subject-full-stop': [2, 'always', '.'],
'subject-case': [2, 'always', 'sentence-case'],
'type-enum': [2, 'always', CommitType[]],
};
}Rules
type-enum
Enforces that commit types match the conventional changelog types.
Severity: 2 (error)
Valid Types:
break,breaking- Breaking changesbuild- Build system changesci,cd- CI/CD changesdeps- Dependency updatesdocs- Documentation changesfeature- New featuresfix- Bug fixesinternal- Internal changesmisc- Miscellaneous changesnew- New featurespatch- Patch fixesrelease- Release commitsrevert- Revert commitssecurity- Security fixesstyle,styles- Style changestest,tests- Test changestype,types- Type system changesupdate- Feature updates
Example:
# ✅ Valid
fix: Fix button styling
new(Button): Add Button component
ci: Update GitHub Actions
# ❌ Invalid
invalid: Invalid commit type
feat: Use 'new' or 'feature' insteadsubject-case
Enforces sentence-case for commit subjects.
Severity: 2 (error)
Format: sentence-case (first letter capitalized, rest lowercase)
Example:
# ✅ Valid
fix: Fix button styling
new(Button): Add Button component
# ❌ Invalid
fix: fix button styling
new(Button): add Button componentsubject-full-stop
Enforces trailing period in commit subjects.
Severity: 2 (error)
Format: Always require trailing period
Example:
# ✅ Valid
fix: Fix button styling.
new(Button): Add Button component.
# ❌ Invalid
fix: Fix button styling
new(Button): Add Button componentscope-case
Allows flexible scope casing (disabled by default).
Severity: 0 (disabled)
Format: start-case (when enabled)
Example:
# All of these are valid:
fix(Button): Fix styling.
fix(button): Fix styling.
fix(BUTTON): Fix styling.body-max-length
No limit on commit body length (disabled by default).
Severity: 0 (disabled)
Commit Message Format
This config enforces the following format:
<type>(<scope>): <subject>.Where:
<type>: One of the valid commit types (see above)<scope>: Optional scope in parentheses<subject>: Sentence-case description ending with a period
Examples
Valid commits:
fix: Fix authentication bug.
new(Button): Add new Button component.
update(Modal): Refactor accessibility support.
ci: Add DangerJS to pipeline.
fix(auth): Fixed a bug with the authentication flow.Invalid commits:
fix: fix bug # Wrong case, missing period
feat: Add feature # Invalid type, missing period
new(Button): add button # Wrong case, missing period
fix: Fix bug # Missing periodCustomization
You can extend and override the configuration:
export default {
extends: ['@rajzik/conventional-commit-lint-config'],
rules: {
'subject-full-stop': [2, 'always', '.'], // Keep default
'subject-case': [2, 'always', 'lower-case'], // Override to lowercase
},
};Integration Examples
GitHub Actions
name: Lint Commits
on:
pull_request:
types: [opened, synchronize]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- run: npm install
- run:
npx commitlint --from ${{ github.event.pull_request.base.sha }} --to
${{ github.sha }} --verbosePre-commit Hook
#!/bin/sh
# .git/hooks/commit-msg
commit_msg=$(cat "$1")
npx commitlint --edit "$1" || exit 1Related Packages
@rajzik/conventional-changelog- Changelog generation@rajzik/conventional-changelog-types- Type definitions@rajzik/danger-configuration- PR validation
