Skip to content

Instantly share code, notes, and snippets.

@paulofierro
Created June 22, 2023 14:50
Show Gist options
  • Save paulofierro/95ed751950c43367d3d13f688df6e287 to your computer and use it in GitHub Desktop.
Save paulofierro/95ed751950c43367d3d13f688df6e287 to your computer and use it in GitHub Desktop.
Pre-commit Example
#!/bin/bash
#
# Add this to your .git/hooks/ folder to run Swiftlint and Swiftformat
#
set -eo pipefail
# Redirect output to stderr
exec 1>&2
if [ `arch` == "arm64" ]; then
tool_path="/opt/homebrew/bin"
else
tool_path="/usr/local/bin"
fi
lint="${tool_path}/swiftlint"
format="${tool_path}/swiftformat"
# Format
if which ${format} >/dev/null; then
${format} MY_PACKAGE_NAME
else
echo "SwiftFormat is not installed." >&2
exit 1
fi
# Lint
if which ${lint} >/dev/null; then
${lint} --fix
${lint}
else
echo "SwiftLint is not installed." >&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment