Skip to content

Instantly share code, notes, and snippets.

@fnoquiq
Last active April 3, 2020 03:15
Show Gist options
  • Save fnoquiq/27a5c3ffab7cd1abf865fb1cdda76f8f to your computer and use it in GitHub Desktop.
Save fnoquiq/27a5c3ffab7cd1abf865fb1cdda76f8f to your computer and use it in GitHub Desktop.
Commit lint config

Commit lint configuration :emoji:

Instale as seguintes dependências:

yarn add -D husky @commitlint/{config-conventional,cli}

Feito isso, adicione ao package.json o seguinte comando:

"husky": {
    "hooks": {
      "commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
    }
  }

Isto será usado para acionar as regras do commitlint.

Crie um arquivo com o nome commitlint.config.js e cole o código abaixo:

module.exports = {
  rules: {
    'type-enum': [
      2,
      'always',
      [
        ':arrow_up_down:',
        ':art:',
        ':bug:',
        ':hammer:',
        ':heavy_check_mark:',
        ':memo:',
        ':rocket:',
        ':see_no_evil:',
        ':tada:'
      ]
    ],
    'body-leading-blank': [2, 'always'],
    'footer-leading-blank': [2, 'always'],
    'header-max-length': [2, 'always', 72],
    'header-min-length': [2, 'always', 10],
    'scope-case': [2, 'always', 'lower-case'],
    'subject-case': [2, 'always', ['sentence-case']],
    'subject-empty': [2, 'never'],
    'subject-full-stop': [2, 'never', ['.']],
    'type-case': [2, 'always', 'lower-case'],
    'type-empty': [2, 'never']
  },
  parserPreset: {
    parserOpts: {
      headerPattern: /^(:\w*:)(?:\((.*?)\))?\s((?:.*(?=\())|.*)(?:\(#(\d*)\))?/,
      headerCorrespondence: ['type', 'scope', 'subject', 'ticket']
    }
  }
}

Eslint husky integration

Adicione o seguinte código ao package.json.

"scripts": {
    ...,
    "lint": "eslint --fix app config database start --ext .js"
},

...,

"husky": {
    "hooks": {
      "pre-commit": "yarn lint"
    }
  }
  

Garanta que o Eslint já esteja configurado, caso queira configurar, procure neste link.


🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment