Skip to content

Commit

Permalink
Merge pull request #583 from IntersectMBO/adjustments-to-formatter
Browse files Browse the repository at this point in the history
Adjustments to formatter
  • Loading branch information
palas authored Jul 11, 2024
2 parents c51e413 + e28fadb commit 6dd96c6
Show file tree
Hide file tree
Showing 141 changed files with 2,492 additions and 2,279 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Fourmolu
name: Check Haskell formatting

on:
merge_group:
Expand All @@ -19,11 +19,12 @@ concurrency:
cancel-in-progress: true

jobs:
check-fourmolu:
check-formatting:
runs-on: ubuntu-latest

env:
FOURMOLU_VERSION: "0.16.2.0"
STYLISH_HASKELL_VERSION: "0.14.5.0"

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

- name: Run Fourmolu over all Haskell files (always succeeds)
- name: Run formatting over all Haskell files (always succeeds)
run: |
git add .
git stash
Expand All @@ -47,14 +57,14 @@ jobs:
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
fourmolu -q -i "$x"
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
done
git --no-pager diff
- name: Run Fourmolu over all modified files
- name: Run formatting over all modified files
run: |
git add .
git stash
Expand All @@ -64,7 +74,7 @@ jobs:
if grep -qE '^#' "$x"; then
echo "$x contains CPP. Skipping."
else
fourmolu -q -i "$x"
"$(git rev-parse --show-toplevel)/scripts/devshell/prettify" "$x"
fi
fi
done
Expand Down
114 changes: 114 additions & 0 deletions .stylish-haskell.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# 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
2 changes: 1 addition & 1 deletion cardano-api-gen/src/Test/Gen/Cardano/Api/Empty.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Test.Gen.Cardano.Api.Empty where

import Test.Gen.Cardano.Api ()
import Test.Gen.Cardano.Api ()

-- | This module is empty, but it is needed to prevent unused-packages warning
11 changes: 7 additions & 4 deletions cardano-api/gen/Test/Gen/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@ import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Coin as Ledger
import qualified Cardano.Ledger.Plutus.CostModels as Plutus
import qualified Cardano.Ledger.Plutus.Language as Alonzo
import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..))
import Cardano.Ledger.Shelley.TxAuxData (Metadatum (..), ShelleyTxAuxData (..))

import qualified Data.Map.Strict as Map
import Data.Word (Word64)
import Hedgehog (Gen, Range)
import Data.Word (Word64)

import Test.Gen.Cardano.Api.Typed (genCostModel, genRational)

import Hedgehog (Gen, Range)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Internal.Range as Range
import Test.Gen.Cardano.Api.Typed (genCostModel, genRational)

genMetadata :: Ledger.Era era => Gen (ShelleyTxAuxData era)
genMetadata = do
Expand Down
19 changes: 11 additions & 8 deletions cardano-api/gen/Test/Gen/Cardano/Api/Byron.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ module Test.Gen.Cardano.Api.Byron
)
where

import Cardano.Api hiding (txIns)
import Cardano.Api.Byron
import Data.Proxy
import Hedgehog
import Test.Gen.Cardano.Api.Typed
import Test.Hedgehog.Roundtrip.CBOR
import Test.Tasty
import Test.Tasty.Hedgehog
import Cardano.Api hiding (txIns)
import Cardano.Api.Byron

import Data.Proxy

import Test.Gen.Cardano.Api.Typed

import Hedgehog
import Test.Hedgehog.Roundtrip.CBOR
import Test.Tasty
import Test.Tasty.Hedgehog

prop_byron_roundtrip_txbody_CBOR :: Property
prop_byron_roundtrip_txbody_CBOR = property $ do
Expand Down
14 changes: 9 additions & 5 deletions cardano-api/gen/Test/Gen/Cardano/Api/Era.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ module Test.Gen.Cardano.Api.Era
)
where

import Cardano.Api hiding (txIns)
import Cardano.Api.Shelley
import Cardano.Api hiding (txIns)
import Cardano.Api.Shelley

import qualified Cardano.Ledger.BaseTypes as Ledger
import qualified Cardano.Ledger.Core as Ledger

import qualified Data.Functor.Identity as Ledger
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary ()
import Test.QuickCheck (Arbitrary (..))

import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Cardano.Ledger.Core.Arbitrary ()

import Test.QuickCheck (Arbitrary (..))

shelleyBasedEraTestConstraints
:: ()
Expand Down
14 changes: 8 additions & 6 deletions cardano-api/gen/Test/Gen/Cardano/Api/Metadata.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@ module Test.Gen.Cardano.Api.Metadata
)
where

import Cardano.Api
import Data.Aeson (ToJSON (..))
import Cardano.Api

import Data.Aeson (ToJSON (..))
import qualified Data.Aeson as Aeson
import qualified Data.Aeson.Key as Aeson
import Data.ByteString (ByteString)
import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import qualified Data.ByteString.Base16 as Base16
import qualified Data.Map.Strict as Map
import Data.Text (Text)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Word (Word64)
import Hedgehog (Gen)
import Data.Word (Word64)

import Hedgehog (Gen)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Internal.Gen as Gen
import qualified Hedgehog.Range as Range
Expand Down
17 changes: 10 additions & 7 deletions cardano-api/gen/Test/Gen/Cardano/Api/ProtocolParameters.hs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
module Test.Gen.Cardano.Api.ProtocolParameters where

import Cardano.Api
import Cardano.Api.Ledger
import Cardano.Api.ProtocolParameters
import Hedgehog (MonadGen)
import Cardano.Api
import Cardano.Api.Ledger
import Cardano.Api.ProtocolParameters

import Test.Gen.Cardano.Api.Typed (genCostModels)

import Test.Cardano.Ledger.Alonzo.Arbitrary ()
import Test.Cardano.Ledger.Conway.Arbitrary ()

import Hedgehog (MonadGen)
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Gen.QuickCheck as Q
import Test.Cardano.Ledger.Alonzo.Arbitrary ()
import Test.Cardano.Ledger.Conway.Arbitrary ()
import Test.Gen.Cardano.Api.Typed (genCostModels)

genStrictMaybe :: MonadGen m => m a -> m (StrictMaybe a)
genStrictMaybe gen =
Expand Down
Loading

0 comments on commit 6dd96c6

Please sign in to comment.