LoginSignup
2
2

More than 5 years have passed since last update.

SwiftLintを導入してみる

Last updated at Posted at 2015-11-25

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

2
2
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
2