Skip to content

Add commit message linting #1382

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

Merged
merged 10 commits into from
Jan 9, 2020
91 changes: 91 additions & 0 deletions .github/COMMIT_CONVENTIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
## Git Commit Message Convention

> This is adapted from [Angular's commit convention](https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-changelog-angular).

#### TL;DR:

Messages must be matched by the following regex:

```js
;/^(revert: )?(feat|fix|polish|docs|style|refactor|perf|test|workflow|ci|chore|types)(\(.+\))?: .{1,50}/
```

#### Examples

Appears under "Features" header, `Server Utils` subheader:

```
feat(server-utils): add 'props' option
```

Appears under "Bug Fixes" header, `Test Utils` subheader, with a link to issue #28:

```
fix(test-utils): handle events on blur

close #28
```

Appears under "Performance Improvements" header, and under "Breaking Changes" with the breaking change explanation:

```
perf(test-utils): improve vdom diffing by removing 'foo' option

BREAKING CHANGE: The 'foo' option has been removed.
```

The following commit and commit `667ecc1` do not appear in the changelog if they are under the same release. If not, the revert commit appears under the "Reverts" header.

```
revert: feat(server-utils): add 'comments' option

This reverts commit 667ecc1654a317a13331b17617d973392f415f02.
```

### Full Message Format

A commit message consists of a **header**, **body** and **footer**. The header has a **type**, **scope** and **subject**:

```
<type>(<scope>): <subject>
<BLANK LINE>
<body>
<BLANK LINE>
<footer>
```

The **header** is mandatory and the **scope** of the header is optional.

### Revert

If the commit reverts a previous commit, it should begin with `revert:`, followed by the header of the reverted commit. In the body, it should say: `This reverts commit <hash>.`, where the hash is the SHA of the commit being reverted.

### Type

If the prefix is `feat`, `fix` or `perf`, it will appear in the changelog. However, if there is any [BREAKING CHANGE](#footer), the commit will always appear in the changelog.

Other prefixes are up to your discretion. Suggested prefixes are `docs`, `chore`, `style`, `refactor`, and `test` for non-changelog related tasks.

### Scope

The scope could be anything specifying the place of the commit change. For example `core`, `compiler`, `ssr`, `v-model`, `transition` etc...

### Subject

The subject contains a succinct description of the change:

- use the imperative, present tense: "change" not "changed" nor "changes"
- don't capitalize the first letter
- no dot (.) at the end

### Body

Just as in the **subject**, use the imperative, present tense: "change" not "changed" nor "changes".
The body should include the motivation for the change and contrast this with previous behavior.

### Footer

The footer should contain any information about **Breaking Changes** and is also the place to
reference GitHub issues that this commit **Closes**.

**Breaking Changes** should start with the word `BREAKING CHANGE:` with a space or two newlines. The rest of the commit message is then used for this.
5 changes: 5 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Hi! I’m really excited that you are interested in contributing to Vue Test Uti
- [Code of Conduct](https://github.com/vuejs/vue/blob/dev/.github/CODE_OF_CONDUCT.md)
- [Issue Reporting Guidelines](#issue-reporting-guidelines)
- [Pull Request Guidelines](#pull-request-guidelines)
- [Committing Changes](#committing-changes)
- [Development Setup](#development-setup)
- [Project Structure](#project-structure)

Expand Down Expand Up @@ -34,6 +35,10 @@ Hi! I’m really excited that you are interested in contributing to Vue Test Uti
- Provide detailed description of the bug in the PR. Live demo preferred.
- Add appropriate test coverage if applicable.

### Committing Changes

Commit messages should follow the [commit message convention](./COMMIT_CONVENTION.md) so that changelogs can be automatically generated. Commit messages will be automatically validated upon commit. If you are not familiar with the commit message convention, you can use `npm run commit` pr `yarn commit` instead of `git commit`, which provides an interactive CLI for generating proper commit messages.

## Development Setup

You will need [Node.js](http://nodejs.org) **version 6+**
Expand Down
33 changes: 30 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build": "lerna run build",
"build:test": "lerna run build:test",
"clean": "lerna clean --yes",
"commit": "git-cz",
"docs": "vuepress dev docs",
"docs:deploy": "scripts/update-docs.sh",
"docs:build": "vuepress build docs",
Expand Down Expand Up @@ -65,7 +66,6 @@
"markdown-it-include": "^1.0.0",
"mocha": "^5.2.0",
"mocha-webpack": "^1.0.1",
"prettier": "^1.16.0",
"rollup": "1",
"rollup-plugin-buble": "^0.19",
"rollup-plugin-commonjs": "10",
Expand All @@ -90,6 +90,33 @@
"webpack-node-externals": "^1.6.0"
},
"devDependencies": {
"@vue/composition-api": "^0.3.2"
"@commitlint/cli": "^8.2.0",
"@commitlint/config-conventional": "^8.2.0",
"@vue/composition-api": "^0.3.2",
"commitizen": "^4.0.3",
"cz-conventional-changelog": "^3.0.2",
"husky": "^3.1.0",
"lint-staged": "^9.5.0",
"prettier": "^1.16.0"
},
"config": {
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
"commitlint": {
"extends": [
"@commitlint/config-conventional"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"lint-staged": {
"*.{js,json,vue,md}": "prettier --check",
"*.{js,vue}": "lint"
}
}
}
Loading