LoginSignup
2
3

More than 3 years have passed since last update.

Xcodeでビルド時にSwiftLintを差分ファイルのみに実行する時に特定のファイルを除外する方法

Posted at

はじめに

表題の通り、Gitの差分ファイルのみにSwiftLintを実行する際に
ファイル単体に対して実行しているからか、SwiftLint設定ファイルのexcludedが機能しませんでした。
詰まったので備忘録的に投稿させていただきます。

実装

SwiftLintを実行するスクリプトの中で、除外の条件文を書きました。
git diffのところの、grepを繋げている箇所です。
最初はif文で書こうとしたのですが、条件が3つ以上になるとどうもうまくいかず、このような実装になっています。
不恰好ですが、除外が機能することが確認出来ました。

RunScript
if which "${PODS_ROOT}/SwiftLint/swiftlint" >/dev/null; then
    git diff --name-only | grep .swift | grep -v Pods/ | grep -v Carthage/ | grep -v R.generated.swift | while read filename; do
        "${PODS_ROOT}/SwiftLint/swiftlint" autocorrect --path "$filename"
        "${PODS_ROOT}/SwiftLint/swiftlint" --path "$filename"
    done
else
    echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi

おわりに

もっと格好良い方法をご存知でしたらコメントいただけると幸いです。。

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