Skip to content

Instantly share code, notes, and snippets.

@aiKrice
Created May 19, 2024 15:31
Show Gist options
  • Select an option

  • Save aiKrice/9047543844798fedf805a0dd02d8df3a to your computer and use it in GitHub Desktop.

Select an option

Save aiKrice/9047543844798fedf805a0dd02d8df3a to your computer and use it in GitHub Desktop.
pre-commit hook with baseline
#!/bin/sh
# Get Swift files that are staged
staged_files=$(git diff --cached --name-only --diff-filter=d | grep ".swift$")
# Check if we have any Swift files to format
if [[ "$staged_files" = "" ]]; then
echo "swiftlint skipped: No source files to lint."
exit 0
fi
echo "$staged_files" | xargs swiftlint --silence-deprecation-warnings --strict --baseline path/to/baseline.json --config .swiftlint.yml
if [ $? -ne 0 ]; then
echo "swiftLint failed, commit denied"
exit 1
fi
echo "$staged_files" | xargs git add
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment