conventional-changelog / conventional-changelog/commitlint
plugins not loaded when using @commitlint/load function
- Dominant language
- TypeScript
- Stars
- 18.7k
- Forks
- 970
- Avg merge
- 7h 33m
- Merged PRs (30d)
- 49
Description
I 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
- [X] 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|
Contributor guide
Research direction
Start by running the provided test.cjs with the accompanying commitlint.config.cjs and inspect the options returned by @commitlint/load, especially plugins. Compare that result with CLI behavior; done means the custom scope-custom rule is available to @commitlint/lint when the configuration is loaded programmatically.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100