Created
May 19, 2024 15:31
-
-
Save aiKrice/9047543844798fedf805a0dd02d8df3a to your computer and use it in GitHub Desktop.
pre-commit hook with baseline
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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