commitlint
repository·master·Indexed 12 days ago
https://github.com/conventional-changelog/commitlintA tool for linting commit messages to ensure they follow the Conventional Commits specification. It includes a CLI (@commitlint/cli) and various configuration packages such as @commitlint/config-conventional, @commitlint/config-angular, and scope-specific configs for Nx and Lerna to automate changelog generation and maintain consistent project history.
What's inside commitlint
- commitlint is a tool used to lint commit messages. It ensures that commit messages follow a specific format or convention (such as Conventional Commits), which is useful for automating changelog generation and maintaining a consistent project history.
Explore community projects for commitlint
masterThe commitlint ecosystem includes several community-maintained projects that extend its functionality or integrate it into specific workflows. These projects are not officially affiliated with the commitlint maintainers.
Key community tools include:
- commitlint.io: A web-based tool to ensure tidy commit messages without local installation.
- commitlint plugin function rules: Allows using functions as rule values to create dynamic rules based on commit messages (e.g., using regular expressions).
- commitlint-plugin-selective-scope: Enables limiting specific scopes per commit type using regular expressions or plain text.
- commitlint-gitlab-ci: A wrapper designed to handle GitLab CI quirks, preventing jobs from failing unexpectedly due to commitlint checks.
- committier: A tool to fix and format commit messages.
- Gitmoji Commit Workflow: A workflow focused on using gitmoji in commits.
Install and use @commitlint/cli
masterThe@commitlint/clipackage provides the command-line interface for linting commit messages. It is used to ensure that commit messages follow a specific convention (like Conventional Commits) by validating them against a configuration.Use commitlint-config-nx-scopes via alias
masterThe packagecommitlint-config-nx-scopesis an alias for@commitlint/config-nx-scopes. Use this configuration to enforce commit message scopes that align with your Nx workspace structure.What is commitlint and the Conventional Commit format
mastercommitlint is a tool used to check if commit messages adhere to the conventional commit format.
The general pattern is:
type(scope?): subjectscopeis optional and supports multiple scopes using delimiters like/,\, or,.- Common types (based on
@commitlint/config-conventional) include:build,chore,ci,docs,feat,fix,perf,refactor,revert,style, andtest.
Examples:
chore: run tests on travis cifix(server): send cors headersfeat(blog): add comment section
Minimum TypeScript version requirements
masterAs of version 18.0.0,commitlintrequires TypeScript v5 or higher. Support for TypeScript v4 was dropped in this release.Minimum Node.js version requirements
masterThe minimum supported Node.js version has changed across major releases. Ensure your environment meets the requirements for your installed version:
- v18.0.0 and later: Requires Node.js v18 or higher.
- v17.0.0 to v17.x.x: Requires Node.js v14 or higher.
- v13.0.0 to v16.x.x: Requires Node.js v12 or higher.
Migrate to pure ESM
masterVersion 19.0.0 introduced a breaking change migrating the project to pure ESM. If you are integratingcommitlintinto a CommonJS project, you may need to adjust your import/require logic or use dynamic imports to accommodate this change.Use functions to define commitlint rules
masterIf your rule configuration needs to be dynamic or depends on external data, you can define a rule as a function instead of a plain array.
commitlintsupports both synchronous functions and asynchronous functions (returning aPromise) that return the rule configuration array[level, applicable, value].Use a synchronous function for simple dynamic logic and an
asyncfunction if you need to perform I/O or fetch configuration from an external source.// Function returning array export default { rules: { "header-max-length": () => [0, "always", 72], }, }; // Async function returning array export default { rules: { "header-max-length": async () => [0, "always", 72], }, };Extend other configurations using `extends`
masterEvery commitlint configuration can inherit from others using the
extendskey. This supports:- npm packages: Use the package ID (e.g.,
'@commitlint/config-conventional'). Note that some packages likelernamight be prefixed ascommitlint-config-lerna. - Local files: Use relative paths to other configuration files (e.g.,
'./commitlint.base.js').
Rules defined in your local configuration will override rules inherited from extended configurations.
export default { extends: [ 'lerna', // prefixed automatically '@commitlint/config-conventional' // scoped package ] }- npm packages: Use the package ID (e.g.,
Use multiple scopes in commit messages
masterCommitlint supports commits that target multiple scopes. To specify multiple scopes, you must separate the segments using delimiters.
By default, the supported delimiters are:
/(forward slash)\(backslash),(comma)
Example of a multi-scope commit:
feat(api,auth): add login endpointYou can customize the allowed set of delimiters using the
scope-delimiter-stylerule.type(scope1,scope2): subjectExtend scoped configuration packages
masterWhen working with scoped npm packages, you have two ways to extend them in your
extendsarray:- Full Package Name: Provide the exact name of the package (e.g.,
@scope/commitlint-config-name). - Scope Shortcut: Provide only the scope.
commitlintwill automatically look for a package following the pattern<scope>/commitlint-config.
If your package does not follow the exact
<scope>/commitlint-configpattern, you must provide the full package name.// Option 1: Full package name export default { extends: ["@commitlint/config-conventional"], }; // Option 2: Scope shortcut (resolves to @coolcompany/commitlint-config) export default { extends: ["@coolcompany"], };- Full Package Name: Provide the exact name of the package (e.g.,