New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

branchlint

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

branchlint

A branch name linter

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

branchlint

A git branch linter to enforce branch naming convention

Installation

npm

npm install --save-dev branchlint

yarn

yarn add -D branchlint

Add .branchlintrc or .branchlintrc.json like

{
  "allowed": ["master"],
  "disallowed": ["develop", "staging"],
  "prefixes": ["feature", "fix", "hotfix", "release"],
  "separator": "/",
  "maxSections": 2
}

You can customize conventions by override options. The default parameters are

{
  "allowed": [],
  "disallowed": [],
  "prefixes": [],
  "regularExpressions": [],
  "separator": "",
  "maxSections": null,
  "msgPrefixNotAllowed": "Branch name \"%s\" is not allowed.\nAllowed branch name prefix is %s and separator is \"%s\"",
  "msgBranchDisallowed": "Pushing to \"%s\" is not allowed, use GitHub Flow.",
  "msgRegexNotMatched": "Pushing to \"%s\" is not allowed, Allowed regex pattern is \"%s\"",
  "msgSeperatorRequired": "Branch \"%s\" must contain a seperator \"%s\".",
  "msgSectionsOver": "Branch name \"%s\" is not allowed\nAllowed max section length is %s"
}

husky integration

You can use husky a git hook library to check naming convention before push

# npm
npm install --save-dev husky
# yarn
yarn add -D husky

Add husky configuration to package.json or .huskyrc to check branch name.

~
"husky": {
  "hooks": {
      "pre-push": "branchlint"
  }
},

Example Conventions

GitHub Flow convention
{
  "allowed": ["master"],
  "disallowed": ["develop", "staging"],
  "prefixes": ["feature", "fix", "hotfix", "release"],
  "separator": "/",
  "maxSections": 2
}
Git Flow convention
{
  "allowed": ["master", "develop"],
  "disallowed": [],
  "prefixes": ["feature", "fix", "hotfix", "release"],
  "separator": "/",
  "maxSections": 2,
  "msgBranchDisallowed": "Pushing to \"%s\" is not allowed, use git-flow."
}

Usage

Options

optiondescription
-c, --configA config file path. Default is .branchlintrc or .brachlintrc.json in current working directory

Configurations

configdescription
allowedAn allowed branch names. default: []
disallowedA disallowed branch names. default: []
prefixesA required branch name prefixes. default: []
regularExpressionsA regular expressions used for validation. default: []
separatorA separator required for branch name. default: ""
maxSectionsMax sections separated by separator parameter. default: null
msgPrefixNotAllowedThe error message when branch name not listed in prefixes is used
msgBranchDisallowedThe error message when disallowed branch name is used
msgRegexNotMatchedThe error message when listed regular expressions in regularExpressions
msgSeperatorRequiredThe error message when required separator is not found
msgSectionsOverThe error message when section count is bigger than maxSections

Test

Run

yarn test

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

LICENSE

MIT

FAQs

Package last updated on 26 Nov 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc