Skip to content

Sharing configurations that use plugins does not work #1942

Closed
@juliuscc

Description

@juliuscc

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
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions