Skip to content

Commit

Permalink
Merge pull request #621 from IntersectMBO/mgalazyn/chore/fix-prettify…
Browse files Browse the repository at this point in the history
…-with-absolute-paths

Fix using of absolute paths in prettify script
  • Loading branch information
carbolymer authored Aug 23, 2024
2 parents 323f576 + a70b647 commit 861fb11
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
16 changes: 2 additions & 14 deletions .github/workflows/check-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,7 @@ jobs:
git stash
for x in $(git ls-tree --full-tree --name-only -r HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
done
git --no-pager diff
Expand All @@ -70,13 +64,7 @@ jobs:
git stash
git fetch origin ${{ github.base_ref }} --unshallow
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD); do
if [ "${x##*.}" == "hs" ]; then
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
done
git --no-pager diff --exit-code
Expand Down
37 changes: 25 additions & 12 deletions scripts/devshell/prettify
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,32 @@ show_help() {
echo " -h, --help Show this help message"
}

# https://no-color.org/
if [[ -z "$NO_COLOR" ]]; then
green_colour="\033[0;32m"
blue_colour="\033[0;34m"
orange_colour="\033[0;33m"
reset_colour="\033[0m"
else
green_colour=""
blue_colour=""
orange_colour=""
reset_colour=""
fi

# Function to run the formatting commands
run_format() {
top_level=$(git rev-parse --show-toplevel)
top_level=$(git rev-parse --show-toplevel)
for file in "$@"; do
if [[ $file == *.hs ]]; then
if grep -qE '^#' "$top_level/$file"; then
echo "$file contains CPP. Skipping."
relative_path=$(realpath --relative-to="$top_level" "$file")
if grep -qE '^#' "$top_level/$relative_path"; then
echo -e "${orange_colour}${relative_path} contains CPP. Skipping.${reset_colour}"
else
echo "Formatting: $file"
fourmolu -q -i "$top_level/$file"
fourmolu -q -i "$top_level/$file"
stylish-haskell -i "$top_level/$file"
echo -e "${green_colour}Formatting: ${blue_colour}${relative_path}${reset_colour}"
fourmolu -q -i "$top_level/$relative_path"
fourmolu -q -i "$top_level/$relative_path"
stylish-haskell -i "$top_level/$relative_path"
fi
fi
done
Expand Down Expand Up @@ -71,16 +85,15 @@ for file in $files; do
if [[ ! -a $file ]]; then
echo "ERROR: $file does not exist"
exit 1
if ![[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
elif ! [[ -f $file ]]; then
echo "ERROR: $file is not a regular file"
exit
fi
done

for tool in stylish-haskell fourmolu
do
if !(which $tool > /dev/null 2>&1); then
if ! (which $tool > /dev/null 2>&1); then
echo "ERROR: $tool is not available!"
echo -e
echo "Try entering the development shell with:"
Expand Down

0 comments on commit 861fb11

Please sign in to comment.