2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Kotlin > KtlintをCommit前にチェックする

2
Posted at

事前設定

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が走ります。

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?