What is @commitlint/load?
The @commitlint/load package is part of the commitlint toolchain, which is used to enforce consistent commit message formats according to various configurable rules. This package specifically handles the loading of commitlint configuration from various sources, allowing users to define rules that commit messages should adhere to in their projects.
Load Configuration
This feature allows the loading of commitlint configuration files. It supports loading from a specified path or from node_modules. The example shows how to load a common configuration that extends '@commitlint/config-conventional'.
const { load } = require('@commitlint/load');
async function loadConfig() {
const config = await load({extends: ['@commitlint/config-conventional']});
console.log(config);
}
loadConfig();
Merge Configurations
This feature demonstrates how to merge custom rules with existing configurations. The example merges a custom rule that restricts commit types to 'feat', 'fix', and 'docs' into the project's commitlint configuration.
const { load } = require('@commitlint/load');
async function mergeConfigs() {
const config = await load({
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs']]
}
}, {cwd: '/path/to/project'});
console.log(config);
}
mergeConfigs();