Skip to content

Instantly share code, notes, and snippets.

@tooszovski
Last active January 18, 2018 07:13
Show Gist options
  • Save tooszovski/4dfa45e87febf9379560d68312002d02 to your computer and use it in GitHub Desktop.
Save tooszovski/4dfa45e87febf9379560d68312002d02 to your computer and use it in GitHub Desktop.
swiftlint script for git diff files with spaces
#!/bin/bash
function addFilesToLint {
filename=""
count=$2
for item in $1
do
if [[ $item == *".swift"* ]]; then
filename+="$item"
export SCRIPT_INPUT_FILE_$count="$filename"
count=$((count + 1))
filename=""
else
filename+="$item "
fi
done
}
count=0
#grep returns result as array divided by newline
targets=$(git ls-files -om --exclude-from=.gitignore | grep -F ".swift")
addFilesToLint "${targets[0]}" $count
targets=$(git diff --cached --name-only | grep -F ".swift$")
addFilesToLint "${targets[0]}" $count
export -p | grep SCRIPT_INPUT_FILE
export SCRIPT_INPUT_FILE_COUNT=$count
swiftlint lint --use-script-input-files
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment