Skip to content

Commit 44484f0

Browse files
committed
Add fourmolu as formatter
1 parent 68f5f4c commit 44484f0

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@ concurrency:
1313
cancel-in-progress: true
1414

1515
jobs:
16+
fourmolu:
17+
runs-on: ubuntu-latest
18+
steps:
19+
# Note that you must checkout your code before running haskell-actions/run-fourmolu
20+
- uses: actions/checkout@v3
21+
- uses: haskell-actions/run-fourmolu@v9
22+
with:
23+
version: "0.14.0.0"
24+
pattern: |
25+
*.hs
26+
!src/Protocols/Cpp.hs
27+
1628
build_mac_windows:
1729
name: Build and run limited tests
1830
runs-on: ${{ matrix.os }}

format.sh

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Help message
5+
show_help() {
6+
local script_name
7+
script_name=$(basename "$0")
8+
echo "Fourmolu formatting Script.
9+
10+
Usage:
11+
$script_name diff Format the current git diff.
12+
$script_name full Format all source files.
13+
$script_name check Check the formatting of the source files.
14+
$script_name (-h | --help)
15+
16+
Options:
17+
-h --help Show this screen."
18+
}
19+
20+
# Main script logic
21+
if [[ "$#" -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then
22+
show_help
23+
exit 0
24+
fi
25+
26+
exclude_files=(
27+
"src/Protocols/Cpp.hs"
28+
)
29+
30+
ghc_opts=(
31+
"-XTemplateHaskell"
32+
)
33+
34+
ghc_opt_flag=""
35+
for opt in "${ghc_opts[@]}"; do
36+
ghc_opt_flag+="-o ${opt} "
37+
done
38+
39+
# Make sure it doesn't matter from where this script is executed
40+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
41+
cd $DIR
42+
43+
if [ $1 == "diff" ] ; then
44+
src_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.hs')
45+
else
46+
src_files=$(find . -type f -name "*.hs")
47+
fi
48+
49+
src_files_str=$(printf "%s\n" "${src_files[@]}" | sed 's| |\\ |g')
50+
exclude_files_str=$(printf "%s\n" "${exclude_files[@]}" | sed 's| |\\ |g')
51+
src_files=$(echo "$src_files_str" | grep -vwE "$exclude_files_str")
52+
53+
if [ -z "$src_files" ]; then
54+
exit 0;
55+
fi
56+
57+
if [[ "$1" == "diff" || "$1" == "full" ]] ; then
58+
fourmolu --mode inplace $src_files
59+
elif [[ "$1" == "check" ]] ; then
60+
fourmolu $ghc_opt_flag --mode check $src_files
61+
else
62+
echo "Expected a single argument, \"full\", \"diff\", \"check\" or \"--help\"" >&2
63+
exit 3
64+
fi

fourmolu.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
indentation: 2
2+
column-limit: 90
3+

0 commit comments

Comments
 (0)