Skip to content

More flexible for setting scope, type and subject limitation by Regular Expression.

License

Notifications You must be signed in to change notification settings

DylanYang0523/validate-commit-msg-regexp

Repository files navigation

validate-commit-msg-regexp

MIT License All Contributors PRs Welcome

Declaration

This is a project base on validate-commit-msg. The original GitHub code and npm modules had been deprecated (not quite sure will they reuse the code again or not), but if you are one of the original users and also if you like the project, welcome to play and discuss together.

Demo

Installation

step.1 👉🏻 npm

This module is distributed via npm which is bundled with node and should be installed as one of your project's devDependencies:

npm install --save-dev validate-commit-msg-regexp

Now, you can choose one setting option from below.

step.2 👉🏻 configuration

You can create and specify options in .vcmrc file. It must be valid JSON file.

{
  "types": [
    "feat", "fix", "docs", "style", "refactor",
    "perf", "test", "build", "ci", "chore", "revert"
  ],
  "scope": {
    "required": false,
    "allowed": ["*"],
    "validate": false,
    "multiple": false,
    "regexpMode": false,
  },
  "warnOnFail": false,
  "maxSubjectLength": 100,
  "subjectPattern": ".+",
  "subjectPatternErrorMsg": "subject does not match subject pattern!",
  "helpMessage": "",
  "autoFix": false
}

or... you can specify options in your package.json file. It must be valid JSON file, as well.

{
  "config": {
    "validate-commit-msg": {
      // ... your custom setting here
    }
  }
}

step.3 👉🏻 git hooks

Set this validation mechanism to where ever you want it can collaborate with, like your git hook system. You can read from Recommend Using⬇️⬇️⬇️

Recommend Using

  • husky ⇨ Git hooks made easy. ⭐⭐⭐⭐⭐
// edit package.json
...
{
  "husky": {
    ...
    "hooks": {
      "...": "...",
      "commit-msg": "validate-commit-msg-regexp",
      "...": "...",
    }
    ...
  }
}
...
  • commitizen ⇨ Help you to create a regular commit msg. ⭐⭐⭐
// edit package.json
...
{
  "scripts": {
    "...": "...",
    "commit": "git-cz",
    "...": "..."
  }
}
...
{
  "config": {
    "commitizen": {
      "path": "./node_modules/cz-conventional-changelog"
    }
  }
}
...

Options

types 🐡

These are the types that are allowed for your commit message. If omitted, the value is what is shown above.

You can also specify: "types": "*" to indicate that you don't wish to validate types.

Or you can specify the name of a module that exports types according to the conventional-commit-types spec, e.g. "types": "conventional-commit-types".

scope 🐙

This object defines scope requirements for the commit message.

  • required ➡ a boolean to define whether a scope is required for all commit messages.

  • allowed ➡ an array of scopes that are allowed for your commit message. You may also define it as "*" which is the default to allow any scope names.

  • validate ➡ a boolean to define whether or not to validate the scope(s) provided.

  • multiple ➡ a boolean to define whether or not to allow multiple scopes.

  • regexpMode ➡ a boolean to define whether or not to validate allowed array with regular expression.

warnOnFail 🦄

If this is set to true errors will be logged to the console, however the commit will still pass.

maxSubjectLength 🐨

This will control the maximum length of the subject.

subjectPattern 🐝

Optional, accepts a RegExp to match the commit message subject against.

subjectPatternErrorMsg 🐧

If subjectPattern is provided, this message will be displayed if the commit message subject does not match the pattern.

helpMessage 🐔

If provided, the helpMessage string is displayed when a commit message is not valid. This allows projects to provide a better developer experience for new contributors.

The helpMessage also supports interpolating a single %s with the original commit message.

autoFix 🐳

If this is set to true, type will be auto fixed to all lowercase, subject first letter will be lowercased, and the commit will pass (assuming there's nothing else wrong with it).

Contributors


Dylan Yang

This project follows the all-contributors specification. Contributions of any kind welcome 🎉🎉🎉

About

More flexible for setting scope, type and subject limitation by Regular Expression.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published