Skip to content

Instantly share code, notes, and snippets.

@CoBug92
Forked from tooszovski/swiftlintdiff.sh
Created January 9, 2018 14:02
Show Gist options
  • Save CoBug92/0252426ee38f6e6bf3cacd6091745663 to your computer and use it in GitHub Desktop.
Save CoBug92/0252426ee38f6e6bf3cacd6091745663 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment