commitlint icon indicating copy to clipboard operation
commitlint copied to clipboard

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

Open shinspiegel opened this issue 5 years ago • 4 comments

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?

shinspiegel avatar Jan 07 '20 14:01 shinspiegel

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 avatar Jan 17 '20 11:01 escapedcat

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,
  },
};

jaworek avatar Jan 17 '20 15:01 jaworek

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

bvbSwyat avatar Oct 09 '20 12:10 bvbSwyat

Looks like the same as #607

FelixSauer avatar Feb 04 '21 10:02 FelixSauer