diff --git a/.github/workflows/check-stylish-haskell.yml b/.github/workflows/check-fourmolu.yml similarity index 64% rename from .github/workflows/check-stylish-haskell.yml rename to .github/workflows/check-fourmolu.yml index ed6796ebf0..5e56c5c46d 100644 --- a/.github/workflows/check-stylish-haskell.yml +++ b/.github/workflows/check-fourmolu.yml @@ -1,4 +1,4 @@ -name: Check Stylish Haskell +name: Check Fourmolu on: merge_group: @@ -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 + diff --git a/.stylish-haskell.yaml b/.stylish-haskell.yaml deleted file mode 100644 index 7218ef5069..0000000000 --- a/.stylish-haskell.yaml +++ /dev/null @@ -1,114 +0,0 @@ -# Stylish-haskell configuration file. - -# Principles: -# -# 1. Amount of indent should not be dependent on the length of the previous line -# 2. Imports lists should be compact -# 3. All linting rules that delete comments should be disabled -# 4. No inline indenting, for example indent of ->, =, <-, as -# 5. Redunant imports and pragmas should be removed -# 6. Consistent syntax -# 7. No trailing whitespaces -# 8. Slightly generous screen width assumed -# 9. All Haskell files in the project are subject to code formatting style -# 10. Import grouping is handled by stylish-haskell - -steps: - # Principle 4 - - simple_align: - cases: false - top_level_patterns: false - # Principle 3 - records: false - - # Import cleanup - - imports: - align: global - - # Principle 1,2 - list_align: with_module_name - - # Principle 4 - pad_module_names: false - - # Principle 2 - long_list_align: inline - - empty_list_align: inherit - - list_padding: 2 - - separate_lists: true - - space_surround: false - - # Principle 10 - group_imports: true - - group_rules: - - match: ^Cardano.Api\> - - match: ^(Cardano|Ouroboros|PlutusCore|PlutusLedgerApi)\> - - match: ^Prelude\> - - match: ^(Control|Codec|Data|Formatting|GHC|Lens|Network|Numeric|Options|Prettyprinter|System|Text)\> - - match: ^(Test.Gen.Cardano.Api)\> - - match: ^(Test.Cardano|Test.Gen.Cardano)\> - - match: ^(Hedgehog|HaskellWorks.Hspec|Test)\> - - - language_pragmas: - style: vertical - - align: false - - # Principle 5 - remove_redundant: true - - # Principle 6 - language_prefix: LANGUAGE - - # Principle 7 - - trailing_whitespace: {} - -# Principle 8 -columns: 100 - -newline: native - -# Principle 9 -# -# These syntax-affecting language extensions are enabled so that -# stylish-haskell wouldn't fail with parsing errors when processing files -# in projects that have those extensions enabled in the .cabal file -# rather than locally. -# -# In particular language extensions with British and American spellings -# that we use should be included here until stylish-haskell supports -# the British spelling. -language_extensions: - - BangPatterns - - ConstraintKinds - - DataKinds - - DefaultSignatures - - DeriveDataTypeable - - DeriveGeneric - - ExistentialQuantification - - FlexibleContexts - - FlexibleInstances - - FunctionalDependencies - - GADTs - - GeneralizedNewtypeDeriving - - LambdaCase - - MultiParamTypeClasses - - MultiWayIf - - OverloadedStrings - - PolyKinds - - RecordWildCards - - ScopedTypeVariables - - StandaloneDeriving - - TemplateHaskell - - TupleSections - - TypeApplications - - TypeFamilies - - ViewPatterns - - ExplicitNamespaces - -cabal: true diff --git a/flake.nix b/flake.nix index 9ceb599bc0..788cd33ccd 100644 --- a/flake.nix +++ b/flake.nix @@ -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]; diff --git a/fourmolu.yaml b/fourmolu.yaml new file mode 100644 index 0000000000..7362755bc9 --- /dev/null +++ b/fourmolu.yaml @@ -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 diff --git a/scripts/githooks/haskell-style-lint b/scripts/githooks/haskell-style-lint index fd52ede1fd..e6f6e32487 100755 --- a/scripts/githooks/haskell-style-lint +++ b/scripts/githooks/haskell-style-lint @@ -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: @@ -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