Skip to content

Commit

Permalink
chore(conventional-commits): validate messages with commitlint
Browse files Browse the repository at this point in the history
  • Loading branch information
jlegrone committed Oct 26, 2017
1 parent 612132e commit 3249727
Show file tree
Hide file tree
Showing 6 changed files with 368 additions and 92 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ install:
before_script:
- yarn build
script:
- if [[ node -v == v4* ]];
then echo "Running node 4; skipping commitlint.";
else ./node_modules/.bin/commitlint --from="$TRAVIS_BRANCH" --to="$TRAVIS_COMMIT";
fi
- yarn install --production
- git aliases
- node lib/remove-config.test
Expand Down
8 changes: 8 additions & 0 deletions .yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"generator-semantic-module": {
"packager": "yarn",
"semantic-release": false,
"commitizen-adapter": "cz-customizable",
"commitlint-config": "@commitlint/config-angular"
}
}
53 changes: 36 additions & 17 deletions .cz-config.js → commitizen.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
const { config } = require('./package.json')

const { types: typeKeys, scope } = config['validate-commit-msg']
const typeSet = new Set(typeKeys)
/* eslint-env node */

const types = [
{
Expand All @@ -16,47 +13,69 @@ const types = [
value: 'docs',
name: 'docs: Documentation only changes'
},
{
value: 'style',
name: `style: Changes that do not affect the meaning of the code
(white-space, formatting, missing semi-colons, etc)`
},
{
value: 'refactor',
name: 'refactor: A code change that neither fixes a bug nor adds a feature'
},
{
value: 'perf',
name: 'perf: A code change that improves performance'
},
{
value: 'test',
name: 'test: Adding missing tests'
},
{
value: 'chore',
name: 'chore: Changes to the build process or auxiliary tools\n and libraries such as documentation generation'
name: `chore: Changes to the build process or auxiliary tools
and libraries such as documentation generation`
},
{
value: 'revert',
name: 'revert: Revert to a commit'
},
{
value: 'WIP',
name: 'WIP: Work in progress'
}
].filter(type => typeSet.has(type.value))

];

const filteredScopes = new Set(['npm'])
const scopes = scope.allowed
.filter(name => !filteredScopes.has(name))
.map(name => ({ name }))
const scopes = [
'aliases',
'branches',
'contains',
'up',
'start',
'hotfix',
'wip',
'undo',
'amend',
'fixup',
'reword',
'edit',
'publish',
'unpublish',
'pushf',
'cleanup',
'cb',
'branch-name',
'develop-branch'
].map(name => ({ name }));

module.exports = {
types,
scopes,
scopeOverrides: {
chore: [
...scopes,
{ name: 'npm' }
]
},
allowCustomScopes: true,
allowBreakingChanges: [
'feat',
'fix',
'perf',
'refactor'
]
}
};
21 changes: 21 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* eslint-env node */

const { types, scopes, allowCustomScopes } = require('./commitizen.config');

const validTypes = types.map((type) => type.value);
const validScopes = scopes.map((scope) => scope.name);
const scopeValidationLevel = allowCustomScopes ? 1 : 2;

module.exports = {
extends: ['@commitlint/config-angular'],

// Add your own rules. See http://marionebl.github.io/commitlint
rules: {
// Apply valid scopes and types
'scope-enum': [scopeValidationLevel, 'always', validScopes],
'type-enum': [2, 'always', validTypes],

// Disable language rule
lang: [0, 'always', 'eng']
}
};
41 changes: 8 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,56 +16,31 @@
"prebuild": "rimraf lib",
"build": "babel scripts --out-dir lib",
"commit": "git-cz",
"commitmsg": "validate-commit-msg",
"commitmsg": "commitlint -e",
"postinstall": "node lib/bootstrap-config",
"prepublish": "npm run build",
"preuninstall": "node lib/remove-config",
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post"
"semantic-release": "semantic-release pre && npm publish --access public && semantic-release post",
"commit:retry": "git-cz --retry"
},
"config": {
"commitizen": {
"path": "node_modules/cz-customizable"
},
"cz-customizable": {
"config": ".cz-config.js"
},
"validate-commit-msg": {
"types": [
"feat",
"fix",
"docs",
"refactor",
"test",
"chore",
"revert"
],
"scope": {
"required": false,
"allowed": [
"aliases",
"repo",
"npm"
],
"validate": true,
"multiple": true
},
"warnOnFail": true,
"maxSubjectLength": 100,
"subjectPattern": ".+",
"subjectPatternErrorMsg": "subject does not match subject pattern!",
"helpMessage": "\nTry running `yarn commit` for help.",
"autoFix": true
"config": "commitizen.config.js"
}
},
"devDependencies": {
"@commitlint/cli": "^4.2.1",
"@commitlint/config-angular": "^4.2.1",
"babel-cli": "^6.24.1",
"babel-preset-env": "^1.6.0",
"commitizen": "^2.9.6",
"cz-customizable": "^5.0.0",
"cz-customizable": "^5.2.0",
"husky": "^0.14.3",
"rimraf": "^2.6.1",
"semantic-release": "^6.3.6",
"validate-commit-msg": "^2.12.2"
"semantic-release": "^6.3.6"
},
"dependencies": {
"chalk": "^2.1.0",
Expand Down
Loading

0 comments on commit 3249727

Please sign in to comment.