Skip to content

Commit

Permalink
ATL-6669: Add pre-commit configuration
Browse files Browse the repository at this point in the history
This commit adds a pre-commit hook that runs scalafmt and instructions
to configure it
  • Loading branch information
EzequielPostan committed Apr 25, 2024
1 parent 2d8f51b commit 2fe2a5c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ In order to keep the code format consistent, we use scalafmt and git hooks, foll
cs install scalafmt
```
- `cp pre-commit .git/hooks/pre-commit`
- `chmod +x .git/hooks/pre-commit`


## IDE / Editor support
Expand Down
25 changes: 25 additions & 0 deletions pre-commit
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

0 comments on commit 2fe2a5c

Please sign in to comment.