Swift用のLinterです
realmが作っているので結構いい感じかもと思い、インストールしてみたのでメモ
https://github.com/realm/SwiftLint
Homebrew
とりあえずHomebrewを更新します
$ brew update
Homebrewのバージョン
$ brew -v
> Homebrew 0.9.5 (git revision 677f; last commit 2015-11-24)
インストール
$ brew install swiftlint
結果
バージョン0.4.0がインストールされました
==> Downloading https://homebrew.bintray.com/bottles/swiftlint-0.4.0.yosemite.bo
######################################################################## 100.0%
==> Pouring swiftlint-0.4.0.yosemite.bottle.tar.gz
🍺 /usr/local/Cellar/swiftlint/0.4.0: 215 files, 55M
ビルド時にlinterを実行するように
プロジェクトのTARGETS > Build Phases にて左上の"+"ボタンをクリックし、"New Run Script Phase"を選択します
Shellは "/bin/sh"を入力
下記ソースコードを追加
if which swiftlint >/dev/null; then
swiftlint
else
echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint"
fi
これでビルドするとErrorかWarningが出るようになります
デフォルトではgithubのスタイルガイドを採用しているようです
https://github.com/github/swift-style-guide
カスタマイズ
プロジェクトのルートディレクトリに.swiftlint.ymlファイルを作成します
これが設定ファイルになりますので、自分なりに編集していきましょう
https://github.com/realm/SwiftLint#configuration