Shareable commitlint config enforcing the angular commit convention
npx @tessl/cli install tessl/npm-commitlint--config-angular@19.8.0@commitlint/config-angular is a shareable commitlint configuration that enforces the Angular commit convention for consistent commit message formatting. It provides comprehensive validation rules for commit message structure, type enforcement, and formatting constraints to maintain clean git history.
npm install --save-dev @commitlint/config-angular @commitlint/cliimport config from "@commitlint/config-angular";For CommonJS environments:
const config = require("@commitlint/config-angular");Internal Implementation:
import typeEnum from "@commitlint/config-angular-type-enum";
export default {
parserPreset: {
parserOpts: { headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/ }
},
rules: {
// ... other rules
"type-enum": typeEnum.rules["type-enum"]
}
};// commitlint.config.js
export default {
extends: ['@commitlint/config-angular']
};With package.json:
{
"commitlint": {
"extends": ["@commitlint/config-angular"]
}
}The main export provides a complete commitlint configuration object for Angular commit convention enforcement.
/**
* Default configuration object for Angular commit convention
* Contains parser preset and validation rules
*/
const config = {
parserPreset: {
parserOpts: {
headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/
}
},
rules: {
"subject-exclamation-mark": [2, "never"],
"body-leading-blank": [1, "always"],
"footer-leading-blank": [1, "always"],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "lower-case"],
"subject-case": [2, "never", ["sentence-case", "start-case", "pascal-case", "upper-case"]],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [2, "always", string[]]
}
};
export default config;Configures commit message parsing for Angular convention format.
/**
* Parser configuration for Angular commit messages
* Supports format: type(scope): subject or type: subject
*/
const parserPreset = {
parserOpts: {
/** Pattern matching Angular commit format: type(scope): subject */
headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/
}
};Supported Formats:
feat: add new featurefix(auth): resolve login issuedocs(readme): update installation instructionsComprehensive set of rules enforcing Angular commit convention standards.
/**
* Validation rules object with rule configurations
* Each rule: [level, condition, value?]
* level: 0 = disabled, 1 = warning, 2 = error
* condition: 'always' | 'never'
*/
const rules = {
// Error-level rules (level 2)
"subject-exclamation-mark": [2, "never"],
"header-max-length": [2, "always", 72],
"scope-case": [2, "always", "lower-case"],
"subject-case": [2, "never", ["sentence-case", "start-case", "pascal-case", "upper-case"]],
"subject-empty": [2, "never"],
"subject-full-stop": [2, "never", "."],
"type-case": [2, "always", "lower-case"],
"type-empty": [2, "never"],
"type-enum": [2, "always", string[]],
// Warning-level rules (level 1)
"body-leading-blank": [1, "always"],
"footer-leading-blank": [1, "always"]
};The type enumeration is imported from @commitlint/config-angular-type-enum package dependency.
import typeEnum from "@commitlint/config-angular-type-enum";
/**
* Type enum dependency providing allowed commit types
* Contains rules object and value function
*/
const typeEnum = {
rules: {
"type-enum": [2, "always", string[]]
},
value: () => string[]
};
/**
* Allowed commit types for Angular convention
* Retrieved from @commitlint/config-angular-type-enum
*/
const allowedTypes = [
"build", // Build system changes
"ci", // CI configuration changes
"docs", // Documentation changes
"feat", // New features
"fix", // Bug fixes
"perf", // Performance improvements
"refactor", // Code refactoring
"revert", // Reverts previous commits
"style", // Code style changes
"test" // Test additions/modifications
];These rules will cause commits to fail:
! for breaking changesfix(auth) ✓, fix(Auth) ✗fix: add feature ✓, fix: Add Feature ✗fix: resolve bug ✓, fix: ✗fix: resolve issue ✓, fix: resolve issue. ✗feat: new feature ✓, FEAT: new feature ✗feat: new feature ✓, : new feature ✗@commitlint/config-angular-type-enumtypeEnum.rules["type-enum"] (imported from dependency)These rules will show warnings but allow commits:
feat: add feature
This is the body text.feat: add feature
Body text here.
BREAKING CHANGE: details here// Valid commit messages
"feat: add user authentication"
"fix(auth): resolve token expiration issue"
"docs: update API documentation"
"test(utils): add unit tests for helpers"
// Invalid commit messages
"FEAT: add feature" // type-case error
"feat: Add Feature" // subject-case error
"feat: resolve issue." // subject-full-stop error
"feat!: breaking change" // subject-exclamation-mark error
"unknown: some change" // type-enum error
"feat: this is a very long commit message that exceeds the maximum length limit" // header-max-length errorThe configuration depends on @commitlint/config-angular-type-enum for type validation rules. This dependency is automatically resolved when the package is installed.
/**
* Type enum dependency providing Angular commit types
* @see https://github.com/conventional-changelog/commitlint
*/
const typeEnum = {
rules: {
"type-enum": [2, "always", ["build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"]]
},
/**
* Function returning the array of allowed types
* @returns {string[]} Array of allowed commit types
*/
value: () => ["build", "ci", "docs", "feat", "fix", "perf", "refactor", "revert", "style", "test"]
};
export default typeEnum;Typically used with:
@commitlint/cli - Command line interfacehusky - Git hooks managementlint-staged - Run linters on staged filesExample integration:
{
"scripts": {
"prepare": "husky install"
},
"devDependencies": {
"@commitlint/cli": "^19.0.0",
"@commitlint/config-angular": "^19.0.0",
"husky": "^8.0.0"
}
}