Skip to content

Commit 121410d

Browse files
committed
Switched to fourmolu, added a CI step to check formatting
1 parent 6920b7e commit 121410d

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,28 @@ jobs:
5656
- name: Run tests
5757
run: |
5858
cabal test all
59+
60+
fourmolu:
61+
runs-on: ubuntu-latest
62+
63+
defaults:
64+
run:
65+
shell: bash
66+
67+
strategy:
68+
fail-fast: false
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Install fourmolu
74+
run: |
75+
FOURMOLU_VERSION="0.16.2.0"
76+
mkdir -p "$HOME/.local/bin"
77+
curl -sL "https://github.com/fourmolu/fourmolu/releases/download/v${FOURMOLU_VERSION}/fourmolu-${FOURMOLU_VERSION}-linux-x86_64" -o "$HOME/.local/bin/fourmolu"
78+
chmod a+x "$HOME/.local/bin/fourmolu"
79+
echo "$HOME/.local/bin" >> $GITHUB_PATH
80+
81+
- name: Run fourmolu
82+
run: ./scripts/fourmolize.sh
83+

project.ncl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ let shellFor = fun ghcver =>
88
let hspkg = import_hs ghcver in {
99
packages = {
1010
haskell-language-server = hspkg "haskell-language-server",
11-
ormolu = hspkg "ormolu",
11+
fourmolu = hspkg "fourmolu",
1212
ghc = organist.import_nix "nixpkgs#haskell.compiler.%{ghcver}",
1313
cabal-install = hspkg "cabal-install",
1414
cabal-fmt = hspkg "cabal-fmt",

scripts/fourmolize.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ $# -gt 0 ]]; then
6+
case "$1" in
7+
--changes)
8+
files=$(git diff --diff-filter=MA --name-only origin/master HEAD -- '*.hs')
9+
if [[ -n "$files" ]]; then
10+
# Run fourmolu on changes compared to `master`.
11+
fourmolu -m inplace $(echo "$files" | grep -v Setup.hs)
12+
fi
13+
;;
14+
*)
15+
echo "Invalid option: $1" >&2
16+
exit 1
17+
;;
18+
esac
19+
else
20+
fourmolu -m inplace $(git ls-files -- '*.hs' | grep -v Setup.hs)
21+
fi
22+
23+
git diff --exit-code

0 commit comments

Comments
 (0)