| name | commitlint |
| description | When setting up commit message validation for a project. When project has commitlint.config.js or .commitlintrc files. When configuring CI/CD to enforce commit format. When extracting commit rules for LLM prompt generation. When debugging commit message rejection errors. |
Commitlint
Validate commit messages against Conventional Commits format using commitlint configuration and rules.
When to Use This Skill
Use this skill when:
- Setting up commitlint for a repository
- Configuring commitlint rules and shareable configurations
- Integrating commitlint with pre-commit hooks or CI/CD pipelines
- Extracting rules from commitlint config to generate LLM prompts for commit message generation
- Validating commit messages programmatically
- Troubleshooting commitlint configuration or validation errors
- Understanding commitlint rule syntax and severity levels
- Detecting commitlint configuration files in a repository
Core Capabilities
Configuration Detection
Commitlint uses cosmiconfig to find configuration files in this priority order:
Dedicated config files:
.commitlintrc
.commitlintrc.json
.commitlintrc.yaml
.commitlintrc.yml
.commitlintrc.js
.commitlintrc.cjs
.commitlintrc.mjs
.commitlintrc.ts
.commitlintrc.cts
commitlint.config.js
commitlint.config.cjs
commitlint.config.mjs
commitlint.config.ts
commitlint.config.cts
Package files:
package.json with commitlint field
package.yaml (PNPM) with commitlint field
Configuration Formats
JavaScript ES Modules (Recommended):
export default {
extends: ['@commitlint/config-conventional'],
};
TypeScript:
import type { UserConfig } from '@commitlint/types';
import { RuleConfigSeverity } from '@commitlint/types';
const config: UserConfig = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [RuleConfigSeverity.Error, 'always', ['feat', 'fix', 'docs']],
},
};
export default config;
JSON:
{
"extends": ["@commitlint/config-conventional"]
}
YAML:
extends:
- "@commitlint/config-conventional"
Rule Configuration
Rules are configured as arrays: [level, applicability, value]
Severity Levels:
| Level | Meaning | TypeScript Enum |
|---|
| 0 | Disabled | RuleConfigSeverity.Disabled |
| 1 | Warning | RuleConfigSeverity.Warning |
| 2 | Error | RuleConfigSeverity.Error |
Applicability:
'always' - Rule must match
'never' - Rule must not match
Example rules:
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']],
'type-empty': [2, 'never'],
'subject-empty': [2, 'never'],
'header-max-length': [2, 'always', 100],
'subject-full-stop': [2, 'never', '.'],
'body-leading-blank': [1, 'always'],
}
Common Configurations
@commitlint/config-conventional
The most widely used shareable configuration. Default error-level rules:
| Rule | Configuration | Pass Example | Fail Example |
|---|
type-enum | ['build', 'chore', 'ci', 'docs', 'feat', 'fix', 'perf', 'refactor', 'revert', 'style', 'test'] | fix: message | foo: message |
type-case | 'lowerCase' | fix: message | FIX: message |
type-empty | never | fix: message | : message |
subject-case | never + ['sentence-case', 'start-case', 'pascal-case', 'upper-case'] | fix: some message | fix: Some Message |
subject-empty | never | fix: message | fix: |
subject-full-stop | never, '.' | fix: message | fix: message. |
header-max-length | 100 | Short header | Header > 100 chars |
body-leading-blank | always (warning) | Blank line before body | No blank line |
body-max-line-length | 100 | Lines <= 100 chars | Line > 100 chars |
footer-leading-blank | always (warning) | Blank line before footer | No blank line |
footer-max-line-length | 100 | Lines <= 100 chars | Line > 100 chars |
Complete Configuration Schema
export default {
extends: ['@commitlint/config-conventional'],
parserPreset: 'conventional-changelog-atom',
formatter: '@commitlint/format',
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'style', 'refactor', 'test', 'chore']],
},
ignores: [(commit) => commit.includes('WIP')],
defaultIgnores: true,
helpUrl: 'https://example.com/commit-guidelines',
prompt: {
messages: {},
questions: {
type: {
description: 'Select the type of change:',
},
},
},
};
CLI Usage
Installation
npm install -D @commitlint/cli @commitlint/config-conventional
yarn add -D @commitlint/cli @commitlint/config-conventional
pnpm add -D @commitlint/cli @commitlint/config-conventional
Common Commands
npx commitlint --last
npx commitlint --from HEAD~5
npx commitlint --from abc1234
echo "feat: add feature" | npx commitlint
npx commitlint < .git/COMMIT_EDITMSG
npx commitlint --edit
npx commitlint --config ./custom-commitlint.config.js
npx commitlint --print-config
npx commitlint --last --strict
Exit Codes
| Code | Meaning |
|---|
| 0 | Success (no errors) |
| 1 | Lint errors found |
| 2 | Warnings found (strict mode only) |
| 3 | Errors found (strict mode) |
| 9 | Config file missing (with -g flag) |
Rule Reference
Type Rules
| Rule | Condition | Default Applicability |
|---|
type-enum | type is found in value | always |
type-case | type is in case value | always, 'lower-case' |
type-empty | type is empty | never |
type-max-length | type has value or less characters | always, Infinity |
type-min-length | type has value or more characters | always, 0 |
Subject Rules
| Rule | Condition | Default Applicability |
|---|
subject-case | subject is in case value | always |
subject-empty | subject is empty | never |
subject-full-stop | subject ends with value | never, '.' |
subject-max-length | subject has value or less characters | always, Infinity |
subject-min-length | subject has value or more characters | always, 0 |
subject-exclamation-mark | subject has exclamation before : | never |
Scope Rules
| Rule | Condition | Default Applicability |
|---|
scope-enum | scope is found in value | always, [] |
scope-case | scope is in case value | always, 'lower-case' |
scope-empty | scope is empty | never |
scope-max-length | scope has value or less characters | always, Infinity |
scope-min-length | scope has value or more characters | always, 0 |
Header Rules
| Rule | Condition | Default Applicability |
|---|
header-case | header is in case value | always, 'lower-case' |
header-full-stop | header ends with value | never, '.' |
header-max-length | header has value or less characters | always, 72 |
header-min-length | header has value or more characters | always, 0 |
header-trim | header has no leading/trailing whitespace | always |
Body Rules
| Rule | Condition | Default Applicability |
|---|
body-leading-blank | body begins with blank line | always |
body-empty | body is empty | never |
body-max-length | body has value or less characters | always, Infinity |
body-max-line-length | body lines have value or less characters (URLs excluded) | always, Infinity |
body-min-length | body has value or more characters | always, 0 |
body-case | body is in case value | always, 'lower-case' |
body-full-stop | body ends with value | never, '.' |
Footer Rules
| Rule | Condition | Default Applicability |
|---|
footer-leading-blank | footer begins with blank line | always |
footer-empty | footer is empty | never |
footer-max-length | footer has value or less characters | always, Infinity |
footer-max-line-length | footer lines have value or less characters | always, Infinity |
footer-min-length | footer has value or more characters | always, 0 |
Case Values
For rules that check case (*-case):
[
'lower-case',
'upper-case',
'camel-case',
'kebab-case',
'pascal-case',
'sentence-case',
'snake-case',
'start-case',
]
Programmatic Usage
Load Configuration
import load from '@commitlint/load';
async function getCommitlintConfig() {
const config = await load();
console.log(config.rules);
return config;
}
Validate Message
import load from '@commitlint/load';
import lint from '@commitlint/lint';
async function validateMessage(message) {
const config = await load();
const result = await lint(message, config.rules);
return {
valid: result.valid,
errors: result.errors,
warnings: result.warnings,
};
}
LLM Integration Patterns
Extract Rules for Prompt Generation
Generate LLM-friendly constraints from commitlint config:
def extract_rules_for_prompt(config: dict) -> str:
"""Extract commitlint rules into LLM-friendly format."""
rules = config.get('rules', {})
prompt_parts = []
if 'type-enum' in rules:
level, applicability, types = rules['type-enum']
if level > 0 and applicability == 'always':
prompt_parts.append(f"Allowed commit types: {', '.join(types)}")
if 'scope-enum' in rules:
level, applicability, scopes = rules['scope-enum']
if level > 0 and applicability == 'always' and scopes:
prompt_parts.append(f"Allowed scopes: {', '.join(scopes)}")
if 'header-max-length' in rules:
level, applicability, length = rules['header-max-length']
if level > 0:
prompt_parts.append(f"Header must be {length} characters or less")
if 'subject-case' in rules:
level, applicability, cases = rules['subject-case']
if level > 0 and applicability == 'never':
prompt_parts.append(f"Subject must NOT use: {', '.join(cases)}")
return '\n'.join(prompt_parts)
Validation Loop
import subprocess
async def validate_with_commitlint(message: str, cwd: Path | None = None) -> tuple[bool, list[str]]:
"""
Validate commit message with commitlint.
Args:
message: The commit message to validate
cwd: Working directory (defaults to current directory)
Returns:
Tuple of (is_valid, error_messages)
"""
result = subprocess.run(
['npx', 'commitlint'],
input=message,
capture_output=True,
text=True,
cwd=cwd,
)
if result.returncode == 0:
return True, []
errors = [line.strip() for line in result.stderr.split('\n') if line.strip()]
return False, errors
Validation loop pattern:
- LLM generates commit message based on diff and rules
- Run commitlint on generated message
- If validation fails, feed errors back to LLM with context
- Retry (max 3 times by default)
- Return final message (valid or best effort after retries)
Common Issues
Node v24 ESM issues:
Use .mjs extension for ES modules config, or add "type": "module" to package.json
Missing extends:
Config without extends or rules fails with "Please add rules" error. Include at least one:
export default {
extends: ['@commitlint/config-conventional'],
};
Empty config error:
Config file must have at least extends or rules defined.
Scope enum empty array:
scope-enum with [] passes all scopes. Use specific array to restrict:
rules: {
'scope-enum': [2, 'always', ['api', 'ui', 'docs']],
}
Subject case trap:
@commitlint/config-conventional uses never with specific cases, meaning those cases are forbidden (not required):
'subject-case': [2, 'never', ['sentence-case', 'start-case', 'pascal-case', 'upper-case']]
Pre-commit Integration
For pre-commit hook integration with commitlint, activate the pre-commit skill:
Skill(command: "pre-commit")
Conventional Commits Reference
For Conventional Commits format specification and examples, activate the conventional-commits skill:
Skill(command: "conventional-commits")
References
Official Documentation
Related Specifications
Source Attribution
This skill was created from reference documentation at the commit-polish repository (2025-12-01)