Skip to content

Commit 3c00f59

Browse files
committed
Add fourmolu as formatter
1 parent 68f5f4c commit 3c00f59

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-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: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
# use array so we can easily append
27+
# Ignore the clash-ghc/src-bin-* since they basically copies of upstream GHC code
28+
readarray -d '' exclude_files < <(find ./clash-ghc/src-bin-* -type f -name "*.hs" -print0)
29+
30+
# Make sure it doesn't matter from where this script is executed
31+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
32+
cd $DIR
33+
34+
if [ $1 == "diff" ] ; then
35+
src_files=$(git diff --cached --name-only --diff-filter=ACMR -- '*.hs')
36+
else
37+
src_files=$(find ./* -type f -name "*.hs")
38+
fi
39+
40+
src_files_str=$(printf "%s\n" "${src_files[@]}" | sed 's| |\\ |g')
41+
exclude_files_str=$(printf "%s\n" "${exclude_files[@]}" | sed 's| |\\ |g')
42+
src_files=$(echo "$src_files_str" | grep -vwE "$exclude_files_str")
43+
44+
if [ -z "$src_files" ]; then
45+
exit 0;
46+
fi
47+
48+
if [[ "$1" == "diff" || "$1" == "full" ]] ; then
49+
fourmolu --mode inplace $src_files
50+
elif [[ "$1" == "check" ]] ; then
51+
fourmolu --mode check $src_files
52+
else
53+
echo "Expected a single argument, \"full\", \"diff\", \"check\" or \"--help\"" >&2
54+
exit 3
55+
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)