Skip to content

Instantly share code, notes, and snippets.

@stephanecopin
Last active January 12, 2021 20:16
Show Gist options
  • Save stephanecopin/71f354310f5c32d14c47 to your computer and use it in GitHub Desktop.
Save stephanecopin/71f354310f5c32d14c47 to your computer and use it in GitHub Desktop.
Run SwiftLint only on untracked/modified (staged or not)/added swift files from git
if which swiftlint >/dev/null; then
count=0
for file_path in $(git ls-files -om --exclude-from=.gitignore | 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
if [ $SCRIPT_INPUT_FILE_COUNT -ne 0 ]; then
swiftlint lint --use-script-input-files
fi
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment