事前設定
command line版のktlintを入れる
brew install ktlint
ktlint --version
pre-commitを導入
brew install pre-commit
pre-commit --versionß
以下のように表示されたら xcode-select --installを行う
Error: python@3.9: the bottle needs the Apple Command Line Tools to be installed.
You can install them, if desired, with:
xcode-select --install
xcode
xcode-select --install
pre-commit-hookの作成
プロジェクトRootで以下を実行する
ktlint --install-git-pre-commit-hook
.git/hooks/ 配下に pre-commitが作成される
pre-commit
# !/bin/sh
# https://github.com/shyiko/ktlint pre-commit hook
git diff --name-only --cached --relative | grep '\.kt[s"]\?$' | xargs ktlint --relative .
if [ $? -ne 0 ]; then exit 1; fi
これでCommitのたびにktlintが走ります。