初心者なんで、Linter無しでSwift書くの不安だなーと思ってたら、Swiftlintがあったので早速インスコ。
https://github.com/realm/SwiftLint
インストール
brew install swiftlint
して、
XCodeのプロジェクトを開いて、Build Phasesを開き、+ボタンをクリックして、[New Run Script Phase]を選択
作成したやつに下記シェルスクリプトを追記
if which swiftlint >/dev/null; then swiftlint else echo "SwiftLint does not exist, download from https://github.com/realm/SwiftLint" fi
これで、ビルドする度に解析が行われます。
文末セミコロンが無しは未だ判るけど、if文の評価式を()で囲まないのを強制するのってどうなんだろ。
かえって読みにくい気がするけど、郷に入っては郷に従います。
設定ファイル
XCodeプロジェクトのルートフォルダに .swiftlint.yml を作ります。
取り敢えずこんな感じにしています。追々改良していきたいです。
disabled_rules: # rule identifiers to exclude from running - trailing_whitespace - type_name - force_cast - line_length excluded: # paths to ignore during linting. Takes precedence over `included`. - Pods type_body_length: - 300 # warning - 400 # error function_body_length: - 300 # warning - 400 # error reporter: "xcode" # reporter type (xcode, json, csv, checkstyle)