Skip to content

Using custom regex on headerPattern ins't creating a valid message #895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
shinspiegel opened this issue Jan 7, 2020 · 4 comments
Open
Labels

Comments

@shinspiegel
Copy link

Hi,

I'm trying to make a custom commit message that starts with the ID of the issue on ours system.
This is a exemple of the message #123 fix: fix issue.

Here is my files

//package.json
  "devDependencies": {
    "@commitlint/cli": "^8.3.4",
    "husky": "^4.0.0"
  }
//commitlint.config.js
module.exports = {
  parserPreset: "./parser-preset.js",
  rules: {
    "type-empty": [2, "never"],
    "subject-empty": [2, "never"]
  }
};
//parser-preset.js
module.exports = {
  parserOpts: {
    headerPattern: /^#(\d*)\s(\w*):\s(.*)$/,
    headerCorrespondence: ["id", "type", "subject"]
  }
};
//.ruskyrc.js
module.exports = {
  hooks: {
    "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
  }
};

By the parser-preset, a commit message with #123 fix: fix issue, should be a valid message, and should send the type and subject correctly for the commitlint. But I'm getting this error:

type may not be empty [type-empty]
✖   subject may not be empty [subject-empty]

✖   found 2 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

What I'm missing? What I did wrong?

@escapedcat
Copy link
Member

escapedcat commented Jan 17, 2020

Not sure, I also tried the "local" example from the docs and it doesn't seem to work (anymore?). Might be a bug. I'll add a label and we'll see.

@escapedcat escapedcat added the bug label Jan 17, 2020
@jaworek
Copy link

jaworek commented Jan 17, 2020

I have similar issue. I want commitlint to only check if commit message contains "#" anywhere. I tried different kind of messages, but I never get error.

Node 12.14.1.

//package.json
  "devDependencies": {
    "@commitlint/cli": "^8.3.5",
    "husky": "^3.0.9"
  },
  "husky": {
      "hooks": {
        "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
      }
  },
//commitlint.config.js
module.exports = {
  parserPreset: './parser-preset.js',
  rules: {
    'body-leading-blank': [0],
    'footer-leading-blank': [0],
    'header-max-length': [0],
    'scope-case': [0],
    'subject-case': [0],
    'subject-empty': [0],
    'subject-full-stop': [0],
    'type-case': [0],
    'type-empty': [0],
    'type-enum': [0],
  },
};
//parser-preset.js
module.exports = {
  parserOpts: {
    headerPattern: /^#\d+\s|\s#\d+\s|#\d+$|^merge/gi,
  },
};

@bvbSwyat
Copy link

bvbSwyat commented Oct 9, 2020

Add extends: ['@commitlint/config-conventional'],
in your module.exports

@FelixSauer
Copy link

Looks like the same as #607

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

5 participants