Last active
February 25, 2024 20:57
-
-
Save aiKrice/6a1a3e0a7f401076585ebb2132f1d916 to your computer and use it in GitHub Desktop.
Detekt: pre-commit
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 kotlin files that are staged | |
| staged_files=$(git diff --cached --name-only --diff-filter=d | grep ".kt$") | |
| # Check if we have any Kotlin files to lint | |
| if [[ "$staged_files" = "" ]]; then | |
| echo "Detekt skipped: No source files to lint." | |
| exit 0 | |
| fi | |
| # Convert newline-separated list to comma-separated list | |
| working_files=$(echo "$staged_files" | tr '\n' ',') | |
| # Remove trailing comma | |
| working_files=${working_files%,} | |
| echo "$staged_files" | xargs detekt -b baseline.xml -c detekt.yml -i $working_files -ex "**/generated/**" | |
| if [ $? -ne 0 ]; then | |
| echo "Detekt failed, commit denied" | |
| exit 1 | |
| fi | |
| # Add changes to git | |
| echo "$staged_files" | xargs git add |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment