Last active
August 18, 2017 03:31
-
-
Save nacho4d/c907745687e3d2f03d4de4fde354b023 to your computer and use it in GitHub Desktop.
use swiftlint to lint only modified or stagged files
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/bash | |
# Usage: | |
# Place this file somewhere in your PATH (and make sure it is executable) then call it like `git lint` | |
# Check swiftlint | |
command -v swiftlint >/dev/null 2>&1 || { echo >&2 "git-lint requires swiftlint but it's not installed. Aborting."; exit 1; } | |
# Create a temp file | |
temp_file=$(mktemp) | |
# Gather all modified and stagged files | |
git ls-files -m | grep ".swift" > ${temp_file} | |
git diff --name-only --cached | grep ".swift" >> ${temp_file} | |
# Make list of unique and sorterd files | |
counter=0 | |
for f in `sort ${temp_file} | uniq` | |
do | |
export SCRIPT_INPUT_FILE_${counter}=${f} | |
counter=`expr $counter + 1` | |
done | |
# Lint | |
if (( counter > 0 )); then | |
export SCRIPT_INPUT_FILE_COUNT=${counter} | |
swiftlint autocorrect --use-script-input-files | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment