以下の内容はhttps://uga-box.hatenablog.com/entry/2024/06/05/000000より取得しました。


【Git】commitlintでコミットコメントを規約に沿わせる

commitlintというコミットコメントを規約に沿わせるツールを知った

commitlint.js.org

始め方はドキュメントより

インストール

$ npm install --save-dev @commitlint/{cli,config-conventional}

コンフィグの用意

echo "export default { extends: ['@commitlint/config-conventional'] };" > commitlint.config.js

huskyのインストール

$ npm install --save-dev husky

huskyはGitフックを使ってtestやlintを実行を制御するもの

前にlintなどのGitフックを実行する

huskyの初期化

$ npx husky init

commilintをコミット時に実行するようにする

echo "npx --no -- commitlint --edit \$1" > .husky/commit-msg

これで準備はできたので、以下のコミットコメントでコミットしてみると

$ git commit -m "foo: this will fail"
⧗   input: foo: this will fail
✖   type must be one of [build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test] [type-enum]

✖   found 1 problems, 0 warnings
ⓘ   Get help: https://github.com/conventional-changelog/commitlint/#what-is-commitlint

husky - commit-msg script failed (code 1)

このように失敗する

初期設定では、コミットコメントにbuild, chore, ci, docs, feat, fix, perf, refactor, revert, style, testのいずれかがなければならないようなので、以下のようなコメントにするとコミットが成功する

$ git commit -m "chore: this will fail"

このルールは以下を見て設定する

commitlint.js.org




以上の内容はhttps://uga-box.hatenablog.com/entry/2024/06/05/000000より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14