Commitlint: Sharing configurations that use plugins does not work

Created on 17 Jun 2020  ·  3Comments  ·  Source: conventional-changelog/commitlint

Sharing configurations that use plugins does not work

We are trying to share a company-wide config so that we can easily have a standard linter with just one line in package.json. We want to use a plugin that adds a rule that otherwise doesn't exist.

  • I have tried our config in a test repo, and then it works great! Thanks for the great tool! ✅
  • When I publish the config on npm _without_ the plugin, I can extend it from other projects. ✅
  • When I publish the config on npm _with_ the plugin, committlint does not recognize the rule. ❌

The configuration looks like this:

const types = require('conventional-commit-types').types;

module.exports = {
  extends: ['@commitlint/config-conventional'],
  plugins: ['subject'],
  rules: {
    'scope-empty': [2, 'always'],
    'type-enum': [2, 'always', Object.keys(types)],
    'subject-case': [0, 'always'],
    'subject-regexp': [2, 'always', /^DAZ-\d+\s.*/],
  },
};

The plugin is commitlint-plugin-subject and we use it to enforce that we can put a JIRA-issue at the beginning of a subject line. Like fix: DAZ-123 Remove bugs.

Expected Behavior

I expect the commit fix: DAZ-123 Remove bugs to pass, and the rule 'subject-regexper' to be recognized.

Current Behavior

When I extend the configuration and run a commit like fix: DAZ-123 Remove bugs I get the following error:

❯ git commit -m "fix: DAZ-123 Remove bugs"
husky > commit-msg (node v13.9.0)
/Users/julius.celik/Coding/temp/commitlint-test/node_modules/@commitlint/cli/lib/cli.js:124
        throw err;
        ^

RangeError: Found invalid rule names: subject-regexp. Supported rule names are: body-case, body-empty, body-leading-blank, body-max-length, body-max-line-length, body-min-length, footer-empty, footer-leading-blank, footer-max-length, footer-max-line-length, footer-min-length, header-case, header-full-stop, header-max-length, header-min-length, references-empty, scope-case, scope-empty, scope-enum, scope-max-length, scope-min-length, signed-off-by, subject-case, subject-empty, subject-full-stop, subject-max-length, subject-min-length, type-case, type-empty, type-enum, type-max-length, type-min-length
    at Object.<anonymous> (/Users/julius.celik/Coding/temp/commitlint-test/node_modules/@commitlint/lint/lib/index.js:76:19)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
husky > commit-msg hook failed (add --no-verify to bypass)

Affected packages

I am not sure but I think it is a core-issue.

  • [ ] cli
  • [x] core
  • [ ] prompt
  • [ ] config-angular

Possible Solution

I am not sure. We really want a fix for this so If you point me in the right direction I could look into submitting a PR tomorrow.

Steps to Reproduce (for bugs)

  1. Init a new repo by running npm init -y && git init
  2. Install commitlint and husky by running npm i -D husky @commitlint/cli
  3. Install our config by running npm install @digitalroute/commitlint-config -D
  4. Run the following echo "module.exports = {extends: ['@digitalroute/commitlint-config']};" > commitlint.config.js
  5. Add the following to package.json: "husky": { "hooks": {"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"}}
  6. Try to run git commit -m "fix: DAZ-123 Remove bugs"

If you do npm install @digitalroute/commitlint-config -D you get the following config:

const types = require('conventional-commit-types').types;

module.exports = {
  extends: ['@commitlint/config-conventional'],
  plugins: ['subject'],
  rules: {
    'scope-empty': [2, 'always'],
    'type-enum': [2, 'always', Object.keys(types)],
    'subject-case': [0, 'always'],
    'subject-regexp': [2, 'always', /^DAZ-\d+\s.*/],
  },
};

You can modify it in node_modules if necessary. If you comment out subject_regexp: ... and plugins: ['subject'], It should work to do a commit.

Context

We want to run a regex on the subject line. The goal is to enforce that all our issues start with 'DAZ-\d+'

Your Environment

| Executable | Version |
| ---------------------: | :------ |
| @commitlint/cli --version | 8.3.5 |
| git --version | git version 2.17.2 (Apple Git-113) |
| node --version | v13.9.0 |

bug

All 3 comments

Hey @juliuscc, thanks for the issue! Not sure when we have time to look into this or point at directions. You could ask in the chat: https://devtoolscommunity.herokuapp.com

Just a status update. We got higher priority tasks so I have not looked too much at this. I will most likely start looking at this by the end of this week or next week. Before I do so I just want a confirmation: Is committing supposed to work as I expected it to?

Maybe @byCedric finds some time to give you a hint for this, when he's back. Might be better to wait for his feedback before you dig into this.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ResDiaryLewis picture ResDiaryLewis  ·  4Comments

EECOLOR picture EECOLOR  ·  3Comments

QuentinRoy picture QuentinRoy  ·  5Comments

n0nick picture n0nick  ·  5Comments

1natsu172 picture 1natsu172  ·  5Comments