Skip to content

Commit

Permalink
Add fourmolu and update hook
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Jul 5, 2024
1 parent beed712 commit cd2d854
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 141 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Stylish Haskell
name: Check Fourmolu

on:
merge_group:
Expand All @@ -19,64 +19,55 @@ concurrency:
cancel-in-progress: true

jobs:
check-stylish-haskell:
check-fourmolu:
runs-on: ubuntu-latest

strategy:
fail-fast: false

env:
# Modify this value to "invalidate" the cabal cache.
CABAL_CACHE_VERSION: "2023-07-12"

STYLISH_HASKELL_VERSION: "0.14.4.0"

STYLISH_HASKELL_PATHS: >
cardano-api
FOURMOLU_VERSION: "0.16.2.0"

steps:
- name: Download stylish-haskell
- name: Download Fourmolu
run: |
version="${{ env.STYLISH_HASKELL_VERSION }}"
fourmolu_path="$(mktemp -d)"
version="${{env.FOURMOLU_VERSION}}"
curl -sL \
"https://github.com/haskell/stylish-haskell/releases/download/v$version/stylish-haskell-v$version-linux-x86_64.tar.gz" \
| tar -C "/tmp" -xz
echo "PATH=/tmp/stylish-haskell-v$version-linux-x86_64:$PATH" >> "$GITHUB_ENV"
"https://github.com/fourmolu/fourmolu/releases/download/v$version/fourmolu-$version-linux-x86_64" > "$fourmolu_path/fourmolu"
echo "PATH=$fourmolu_path:$PATH" >> "$GITHUB_ENV"
chmod u+rwx "$fourmolu_path/fourmolu"
- uses: actions/checkout@v3

- name: Run stylish-haskell over all Haskell files (always succeeds)
- name: Run Fourmolu over all Haskell files (always succeeds)
run: |
git add .
git stash
for x in $(git ls-tree --full-tree --name-only -r HEAD ${{ env.STYLISH_HASKELL_PATHS }}); do
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
stylish-haskell -i "$x"
fourmolu -q -i "$x"
fi
fi
done
git --no-pager diff
- name: Run stylish-haskell over all modified files
- name: Run Fourmolu over all modified files
run: |
git add .
git stash
git fetch origin ${{ github.base_ref }} --unshallow
for x in $(git diff --name-only --diff-filter=ACMR origin/${{ github.base_ref }}..HEAD ${{ env.STYLISH_HASKELL_PATHS }}); do
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
stylish-haskell -i "$x"
fourmolu -q -i "$x"
fi
fi
done
git --no-pager diff --exit-code
114 changes: 0 additions & 114 deletions .stylish-haskell.yaml

This file was deleted.

1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
haskell-language-server.src = nixpkgs.haskell-nix.sources."hls-2.6";
hlint = "3.6.1";
stylish-haskell = "0.14.5.0";
fourmolu = "0.16.2.0";
};
# and from nixpkgs or other inputs
shell.nativeBuildInputs = with nixpkgs; [gh jq yq-go actionlint shellcheck cabal-head];
Expand Down
17 changes: 17 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
indentation: 2
column-limit: 100
function-arrows: leading
comma-style: leading
import-export-style: leading
indent-wheres: true
record-brace-space: true
newlines-between-decls: 1
haddock-style: single-line
haddock-style-module:
let-style: auto
indent-wheres: false
in-style: right-align
unicode: never
respectful: false
fixities: []
single-constraint-parens: never
4 changes: 2 additions & 2 deletions scripts/githooks/haskell-style-lint
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/sh
# This script validates the staged changes in Haskell files using stylish-haskell and hlint and returns non-zero
# This script validates the staged changes in Haskell files using fourmolu and hlint and returns non-zero
# code when there are linting or style issues.
#
# To set this script as your pre-commit hook, use the following command:
Expand All @@ -13,7 +13,7 @@ for x in $(git diff --staged --name-only --diff-filter=ACM "*.hs" | tr '\n' ' ')
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
stylish-haskell -i "$x"
fourmolu -q -i "$x"
fi
hlint "$x" || hlint_rc="1"
done
Expand Down

0 comments on commit cd2d854

Please sign in to comment.