ladder99
ladder99 copied to clipboard
Use `commitlint`
I believe that using commitlint is a nice tool to create short, descriptive commit messages. Moreover, we could later create (release) changelogs from them, once we learn to follow the rules.
Dev behavior change. Use it and close the task.
This my commitlint.config.json in my other project. Again, we can discuss individual configs; nothing is built into stone.
commitlint.config.json
const {readdirSync} = require('fs')
module.exports = {
extends: ['@commitlint/config-conventional'],
formatter: '@commitlint/format',
// TODO: Change this URL to our Wiki page with the description of the commit message format.
helpUrl: 'https://github.com/conventional-changelog/commitlint/#what-is-commitlint',
parserPreset: {
parserOpts: {
issuePrefixes: ['#']
}
},
rules: {
'body-case': [2, 'always', 'sentence-case'],
'body-empty': [0, 'never'],
'body-full-stop': [2, 'always', '.'],
'body-leading-blank': [2, 'always'],
'body-max-line-length': [0, 'never', 0],
'footer-empty': [0, 'never'],
'footer-leading-blank': [2, 'always'],
'footer-max-line-length': [0, 'never', 0],
'header-full-stop': [2, 'never', '.'],
'header-max-length': [0, 'never', 0],
'scope-enum': async () => {
const apps = readdirSync('apps', {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
const libs = readdirSync('libs', {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
let allowedScopes = [];
[...apps, ...libs].forEach(a => {
const modules = readdirSync(`${apps.indexOf(a) > -1 ? 'apps' : 'libs'}/${a}/src`, {withFileTypes: true})
.filter(dirent => dirent.isDirectory())
.map(dirent => dirent.name)
allowedScopes.push(a)
})
return [2, 'always', [...allowedScopes]]
},
'subject-case': [1, 'always', 'lower-case'],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
]
]
}
}