Skip to content

Instantly share code, notes, and snippets.

@joeblau
Created June 1, 2019 16:57
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save joeblau/a82bd6c353a076adb3698585c5d56d94 to your computer and use it in GitHub Desktop.
Save joeblau/a82bd6c353a076adb3698585c5d56d94 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
@bobspryn
Copy link

bobspryn commented Aug 6, 2020

👋 Thanks Joe!

@vmalyi
Copy link

vmalyi commented Aug 14, 2020

Don't forget to grant execution permission to this newly-added pre-commit file: chmod +x .git/hooks/pre-commit

@martinmose
Copy link

Cool, thanks Joe 💪

@markst
Copy link

markst commented Jul 27, 2022

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment