-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ATL-6669: Add pre-commit configuration
This commit adds a pre-commit hook that runs scalafmt and instructions to configure it
- Loading branch information
1 parent
2d8f51b
commit 2fe2a5c
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Define the location of the scalafmt executable | ||
SCALAFMT="scalafmt" | ||
|
||
# Define the files you want to format | ||
FILES=$(git diff --cached --name-only --diff-filter=ACMR | grep '\.scala$') | ||
|
||
# Check if any Scala files are staged for commit | ||
if [ -n "$FILES" ]; then | ||
echo "Running scalafmt on staged Scala files..." | ||
# Run scalafmt on staged Scala files | ||
$SCALAFMT --test --non-interactive $FILES | ||
|
||
# Check if scalafmt made any changes | ||
if [ $? -ne 0 ]; then | ||
echo "Scalafmt found formatting issues. Aborting commit." | ||
exit 1 | ||
fi | ||
|
||
echo "Scalafmt formatting check passed." | ||
fi | ||
|
||
# If no Scala files are staged, exit without doing anything | ||
exit 0 |