# branchlint

> A branch name linter

Latest version **0.0.2** (published 2019-11-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install branchlint
pnpm add branchlint
yarn add branchlint
bun add branchlint
```

Provides the command `branchlint`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2019-11-26 |
| First published | 2019-11-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | Shuhei Hayashibara |
| Maintainers | shufo |

## Links

- npm: https://www.npmjs.com/package/branchlint
- Repository: https://github.com/shufo/branchlint
- npm.io page: https://npm.io/package/branchlint

## Dependencies (8)

- [esm](https://npm.io/package/esm.md) ^3.2.25
- [chalk](https://npm.io/package/chalk.md) ^3.0.0
- [yargs](https://npm.io/package/yargs.md) ^14.2.0
- [lodash](https://npm.io/package/lodash.md) ^4.17.15
- [sprintf-js](https://npm.io/package/sprintf-js.md) ^1.1.2
- [cosmiconfig](https://npm.io/package/cosmiconfig.md) ^6.0.0
- [app-root-path](https://npm.io/package/app-root-path.md) ^3.0.0
- [git-branch-is](https://npm.io/package/git-branch-is.md) ^3.0.0

## Recent versions

- 0.0.2 (latest) — 2019-11-26
- 0.0.1 — 2019-11-26

## README

# 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

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

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

```json
{
  "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](https://github.com/typicode/husky) a git hook library to check naming convention before push

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

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

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

### Example Conventions

#### GitHub Flow convention

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

#### Git Flow convention

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

## Usage

### Options

|           option |                                                                                        description |
| ---------------: | -------------------------------------------------------------------------------------------------: |
| `-c`, `--config` | A config file path. Default is `.branchlintrc` or `.brachlintrc.json` in current working directory |

### Configurations

|                config |                                                         description |
| --------------------: | :------------------------------------------------------------------ |
|             `allowed` |                              An allowed branch names. default: `[]` |
|          `disallowed` |                            A disallowed branch names. default: `[]` |
|            `prefixes` |                      A required branch name prefixes. default: `[]` |
|  `regularExpressions` |                        A regular expressions used for validation. default: `[]` |
|           `separator` |                 A separator required for branch name. default: `""` |
|         `maxSections` |    Max sections separated by `separator` parameter. default: `null` |
| `msgPrefixNotAllowed` | The error message when branch name not listed in `prefixes` is used |
| `msgBranchDisallowed` |               The error message when disallowed branch name is used |
|                    `msgRegexNotMatched` |The error message when listed regular expressions in `regularExpressions`|
|`msgSeperatorRequired`|The error message when required separator is not found|
|`msgSectionsOver`|The 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

---
_Source: https://npm.io/package/branchlint · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
