Skip to content

Instantly share code, notes, and snippets.

@micheltlutz
Forked from joeblau/pre-commit
Created July 16, 2020 18:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micheltlutz/9ac3b13690bcc23abe9add34a3f326ec to your computer and use it in GitHub Desktop.
Save micheltlutz/9ac3b13690bcc23abe9add34a3f326ec to your computer and use it in GitHub Desktop.
Pre commit git hook to run SwiftLint and SwiftFormat
#!/bin/bash
# Place this file in `.git/hooks/`
if which swiftlint >/dev/null; then
swiftlint autocorrect
else
echo "warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint"
fi
git diff --diff-filter=d --staged --name-only | grep -e '\(.*\).swift$' | while read line; do
swiftformat "${line}";
git add "$line";
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment