Last active
April 13, 2019 05:17
-
-
Save CraigsOverItAll/2e341162c585250e80216b6a510713d3 to your computer and use it in GitHub Desktop.
GitLint an Xcode build phase run script to help apply Swift linting rules to your code base Incrementally
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
function gitlint { | |
count=0 | |
for file_path in $(git ls-files -om --exclude-from=.gitignore -- ':!:Pods/**'| grep ".swift$"); do | |
export SCRIPT_INPUT_FILE_$count=$file_path | |
count=$((count + 1)) | |
done | |
for file_path in $(git diff --cached --name-only | grep ".swift$"); do | |
export SCRIPT_INPUT_FILE_$count=$file_path | |
count=$((count + 1)) | |
done | |
export SCRIPT_INPUT_FILE_COUNT=$count | |
swiftlint lint --use-script-input-files | |
exit 0 | |
} | |
if which swiftlint >/dev/null; then | |
gitlint | |
elif which brew >/dev/null; then | |
brew install swiftlint | |
gitlint | |
else | |
echo "warning: SwiftLint not available, please try installing with homebrew (https://brew.sh)" | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment