Skip to content

Instantly share code, notes, and snippets.

@CraigsOverItAll
Last active April 13, 2019 05:17
Show Gist options
  • Save CraigsOverItAll/2e341162c585250e80216b6a510713d3 to your computer and use it in GitHub Desktop.
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
#!/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