ladder99 icon indicating copy to clipboard operation
ladder99 copied to clipboard

Use `commitlint`

Open tukusejssirs opened this issue 3 years ago • 2 comments

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.

tukusejssirs avatar Dec 15 '22 12:12 tukusejssirs

Dev behavior change. Use it and close the task.

MRIIOT avatar Dec 17 '22 00:12 MRIIOT

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'
         ]
      ]
   }
}

tukusejssirs avatar Dec 17 '22 13:12 tukusejssirs