plugins not loaded when using @commitlint/load function
See original GitHub issueI am configuring a commit linting setup and for this also plugins with custom rules.
I have no issue creating the plugins and running them when the cli, something like this echo "feat(t1-1234): hello there" | npx commitlint
. My plugins are executed correctly and everything.
I now want to utilize your @commitlint/load function with the @commitlint/lint function for CI purposes. But the load function does not seem to provide the plugins.
I therefor get the error message UnhandledPromiseRejectionWarning: RangeError: Found invalid rule names: scope-custom. Supported rule names are:…
If I print what is loaded, plugins will have the following content: “plugins”:{“local”:{“rules”:{}}}
Affected packages
- cli
- core
- prompt
- config-angular
Steps to Reproduce (for bugs)
Should be easy to reproduce. I don’t think I have any special configurations or anything.
I have this test.cjs for linting a string. Commitlint.config.cjs has my configuration setup. I’ve also tried to create this as a npm package and just using extends on that package.
test.cjs
const load = require("@commitlint/load").default;
const lint = require("@commitlint/lint").default;
load()
.then((opts) => {
console.log("finished", JSON.stringify(opts));
lint(
"fix: bar",
opts.rules,
opts.parserPreset ? { parserOpts: opts.parserPreset.parserOpts } : {}
);
})
.then((report) => console.log(report));
commitlint.config.cjs
const typeEnum = [
"build",
"chore",
"ci",
"docs",
"feat",
"fix",
"perf",
"refactor",
"revert",
"sdk",
"style",
"test",
];
const configuration = {
extends: ['@commitlint/config-conventional'],
parserOpts: {
headerPattern: /^(\w+)\((t1)|(t3)|(t4)|(t4)|(t5)-[0-9]+\):[ ]{1}(\w{1}.+\w{1})$/,
headerCorrespondence: ['type', 'scope', 'subject'],
},
rules: {
"subject-case": [2, "always", "lower-case"],
"subject-full-stop": [2, "never", "."],
"subject-max-length": [2, "always", 50],
"scope-max-length": [2, "always", 10],
"scope-min-length": [2, "always", 6],
"type-enum": [2, "always", typeEnum],
"scope-custom": [2, "always"],
},
plugins: [
{
rules: {
"scope-custom": ({ scope }) => {
try {
const regex = /^((t1)|(t3)|(t4)|(t4)|(t5))-[0-9]+$/g;
const found = scope.match(regex);
if (found) {
return [true, ''];
} else {
return [false, `Your scope should match regex: ${regex}`];
}
} catch (_) {
return [false, "Your commit message should contain a scope"];
}
},
},
},
],
};
module.exports = configuration;
Context
Your Environment
Executable | Version |
---|---|
commitlint --version |
17.0.3 |
git --version |
2.34.1.windows |
node --version |
14.18.0 |
Issue Analytics
- State:
- Created a year ago
- Comments:5
Top GitHub Comments
After looking into the code, it was obvious what had to be done to fix my issue. If your rules depends on a plugin you need to pass those explicitly to the lint function.
Something like this below.
I would consider this matter closed, but maybe some documentation would be appreciated by the next guy.
If you have some time a PR for the docs that would be great. You know best what you would have needed.