question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

plugins not loaded when using @commitlint/load function

See original GitHub issue

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
  • 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:open
  • Created a year ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
flemminglundahlcommented, Sep 5, 2022

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.

const load = require("@commitlint/load").default;
const lint = require("@commitlint/lint").default;

const config = load();

lint(commit, config.rules, {
  parserOpts: config.parserPreset.parserOpts,
  plugins: config.plugins,
});

I would consider this matter closed, but maybe some documentation would be appreciated by the next guy.

0reactions
escapedcatcommented, Sep 5, 2022

If you have some time a PR for the docs that would be great. You know best what you would have needed.

Read more comments on GitHub >

github_iconTop Results From Across the Web

commitlint-plugin-function-rules - npm package - Snyk
The npm package commitlint-plugin-function-rules was scanned for known vulnerabilities and missing license, and no issues were found. Thus the package was ...
Read more >
Marketplace Plugins are not loaded
Hello, I'm working for a company and I currently have access to https://plugins.jetbrains.com/ but inside IntelliJ, when I browse the...
Read more >
Cordova plugins not working - Stack Overflow
Android 4.4 device (coupled with USB); Using Terminal; not Eclipse. What happens: Using cordova run --release successfully builds and signs the .apk and...
Read more >
Plugins not loading in Ableton 11 1? Try this - YouTube
Read My Bestselling Book "The Mental Game of Electronic Music Production" https://amzn.to/3HI1s3q➡Read My Newest Book " The Process For ...
Read more >
Installing plug-ins - FileMaker Pro
•Write a script and use the Insert File script step to place the plug-in in ... •FileMaker Pro will not load a plug-in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found