-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
edf1038
commit eef43b4
Showing
2 changed files
with
66 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Initialize variables | ||
BRANCH_DEST=master | ||
FOLDERS_TO_CHECK=("lib" "test") | ||
|
||
# Check if dart is available | ||
if command -v dart &> /dev/null | ||
then | ||
DART_COMMAND="dart" | ||
else | ||
echo "Error: Failed to find dart in your path" | ||
exit 1 | ||
fi | ||
|
||
DART_FORMAT_COMMAND="${DART_COMMAND} format -l 80" | ||
|
||
# Initialize empty strings to store files that fail formatting | ||
FILES_NEEDING_FORMAT="" | ||
|
||
# Get changed files from git | ||
CHANGED_FILES=$(git diff --name-only origin/${BRANCH_DEST}) | ||
GIT_DIFF_EXIT_CODE=$? | ||
if [ $GIT_DIFF_EXIT_CODE -ne 0 ]; then | ||
echo "Error: Failed to execute git diff" | ||
exit $GIT_DIFF_EXIT_CODE | ||
fi | ||
|
||
# Exit early if no files have changed | ||
if [ -z "$CHANGED_FILES" ]; then | ||
echo "No files have changed." | ||
exit 0 | ||
fi | ||
|
||
# Check each changed file for formatting and analysis issues | ||
for FOLDER in "${FOLDERS_TO_CHECK[@]}" | ||
do | ||
for FILE in $(echo "${CHANGED_FILES}" | grep "${FOLDER}.*.dart$") | ||
do | ||
# Check for formatting issues | ||
${DART_FORMAT_COMMAND} -o none --show none --set-exit-if-changed "${FILE}" | ||
FORMAT_EXIT_CODE=$? | ||
if [ $FORMAT_EXIT_CODE -ne 0 ]; then | ||
FILES_NEEDING_FORMAT="${FILES_NEEDING_FORMAT}\n$FILE" | ||
fi | ||
done | ||
done | ||
|
||
# Report formatting issues | ||
if [ ! -z "$FILES_NEEDING_FORMAT" ]; then | ||
echo -e "\nThe following files need formatting:\n$FILES_NEEDING_FORMAT\n" | ||
fi | ||
|
||
# If any issues are found, exit with error code | ||
if [ ! -z "$FILES_NEEDING_FORMAT" ] ; then | ||
exit 1 | ||
else | ||
echo "No formatting or analysis issues found in the changed files." | ||
exit 0 | ||
fi |
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,6 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Setup pre-commit hooks | ||
git config core.hooksPath .githooks | ||
chmod +x .githooks/pre-commit | ||
|