Skip to content

Commit

Permalink
Adopt diff-friendly import style. (#4173)
Browse files Browse the repository at this point in the history
## Summary

This PR adjusts our `stylish-haskell` configuration to always import
each symbol on a separate line. Example:
```hs
import Some.Module.A
    ( SomeSymbolA1
    , SomeSymbolA2
    )
import Some.Module.B
    ( SomeSymbolB1
    , SomeSymbolB2
    , SomeSymbolB3
    , SomeSymbolB4
    )
````

## Details

This change has several advantages:
1. **Better cross-version compatibility**: this configuration produces
[almost exactly the
same](731127c)
output across versions `0.11.0.3` and `0.14.5.0` of `stylish-haskell`
(current and latest versions respectively).
1. **Better cross-tool compatibility**: the output is almost identical
to that produced by **`fourmolu`**. (See experimental `fourmolu` branch
[here](https://github.com/cardano-foundation/cardano-wallet/pull/4061/files).)
1. **Improved diff-friendliness**: we virtually eliminate the problem
where adding or removing a single import can lead to a multi-line diff.

Adopting this style will make it easier to move to GHC `9.2` or `9.6`,
both of which no longer work with our current version of
`stylish-haskell`.

## Related Issues

Without this change in our configuration, upgrading `stylish-haskell`
from version `0.11.0.3` to `0.14.5.0` exposes us to the following
regression:
haskell/stylish-haskell#462
  • Loading branch information
jonathanknowles committed Oct 20, 2023
2 parents 342d3a9 + 406576c commit b534f20
Show file tree
Hide file tree
Showing 554 changed files with 19,885 additions and 7,639 deletions.
2 changes: 1 addition & 1 deletion .stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# https://github.com/jaspervdj/stylish-haskell/blob/master/data/stylish-haskell.yaml
# for usage.

columns: 80 # Should match .editorconfig
columns: 1 # Force diff-friendly import style (one line per symbol).
steps:
- imports:
align: none
Expand Down
57 changes: 40 additions & 17 deletions lib/address-derivation-discovery/lib/Cardano/Byron/Codec/Cbor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,39 +44,62 @@ module Cardano.Byron.Codec.Cbor
import Prelude

import Cardano.Address.Derivation
( XPub, xpubToBytes )
( XPub
, xpubToBytes
)
import Cardano.Wallet.Address.Derivation
( Depth (..), DerivationType (..), Index (..) )
( Depth (..)
, DerivationType (..)
, Index (..)
)
import Cardano.Wallet.Primitive.Passphrase
( Passphrase (..) )
( Passphrase (..)
)
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
( Address (..)
)
import Cardano.Wallet.Primitive.Types.Hash
( Hash (..) )
( Hash (..)
)
import Cardano.Wallet.Primitive.Types.ProtocolMagic
( ProtocolMagic (..) )
( ProtocolMagic (..)
)
import Cardano.Wallet.Primitive.Types.Tx
( unsafeCoinToTxOutCoinValue )
( unsafeCoinToTxOutCoinValue
)
import Cardano.Wallet.Primitive.Types.Tx.TxIn
( TxIn (..) )
( TxIn (..)
)
import Cardano.Wallet.Primitive.Types.Tx.TxOut
( TxOut (..) )
( TxOut (..)
)
import Control.Monad
( replicateM, when )
( replicateM
, when
)
import Crypto.Error
( CryptoError (..), CryptoFailable (..) )
( CryptoError (..)
, CryptoFailable (..)
)
import Crypto.Hash
( hash )
( hash
)
import Crypto.Hash.Algorithms
( Blake2b_224, SHA3_256 )
( Blake2b_224
, SHA3_256
)
import Data.ByteString
( ByteString )
( ByteString
)
import Data.Digest.CRC32
( crc32 )
( crc32
)
import Data.Either.Extra
( eitherToMaybe )
( eitherToMaybe
)
import Data.Word
( Word8 )
( Word8
)

import qualified Cardano.Wallet.Primitive.Types.Coin as Coin
import qualified Cardano.Wallet.Primitive.Types.TokenBundle as TokenBundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,29 @@ import Cardano.Wallet.Address.Derivation
import Cardano.Wallet.Address.Derivation.Shared
()
import Cardano.Wallet.Address.Derivation.SharedKey
( SharedKey (..) )
( SharedKey (..)
)
import Cardano.Wallet.Primitive.Types.Address
( Address, AddressState (..) )
( Address
, AddressState (..)
)
import Control.Lens
( Iso', iso, withIso )
( Iso'
, iso
, withIso
)
import Data.Kind
( Type )
( Type
)
import Data.Map.Strict
( Map )
( Map
)
import Data.Type.Equality
( type (==) )
( type (==)
)
import Fmt
( Buildable (..) )
( Buildable (..)
)

import qualified Cardano.Wallet.Address.Discovery.Random as Rnd
import qualified Cardano.Wallet.Address.Discovery.Sequential as Seq
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,47 +80,74 @@ module Cardano.Wallet.Address.Derivation
import Prelude

import Cardano.Address.Derivation
( XPrv, XPub )
( XPrv
, XPub
)
import Cardano.Mnemonic
( SomeMnemonic )
( SomeMnemonic
)
import Cardano.Wallet.Primitive.NetworkId
( HasSNetworkId (..), SNetworkId )
( HasSNetworkId (..)
, SNetworkId
)
import Cardano.Wallet.Primitive.Passphrase.Types
( Passphrase (..) )
( Passphrase (..)
)
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
( Address (..)
)
import Cardano.Wallet.Primitive.Types.RewardAccount
( RewardAccount (..) )
( RewardAccount (..)
)
import Control.Applicative
( (<|>) )
( (<|>)
)
import Control.DeepSeq
( NFData )
( NFData
)
import Control.Monad
( (>=>) )
( (>=>)
)
import Data.Bifunctor
( first )
( first
)
import Data.Bits
( (.&.) )
( (.&.)
)
import Data.ByteArray
( ByteArray, ByteArrayAccess )
( ByteArray
, ByteArrayAccess
)
import Data.ByteArray.Encoding
( Base (..), convertFromBase, convertToBase )
( Base (..)
, convertFromBase
, convertToBase
)
import Data.ByteString
( ByteString )
( ByteString
)
import Data.Kind
( Type )
( Type
)
import Data.List.NonEmpty
( NonEmpty (..) )
( NonEmpty (..)
)
import Data.Maybe
( fromMaybe )
( fromMaybe
)
import Data.Proxy
( Proxy (..) )
( Proxy (..)
)
import Data.Scientific
( Scientific, toBoundedInteger )
( Scientific
, toBoundedInteger
)
import Data.String
( fromString )
( fromString
)
import Data.Text
( Text )
( Text
)
import Data.Text.Class
( CaseStyle (..)
, FromText (..)
Expand All @@ -130,23 +157,36 @@ import Data.Text.Class
, toTextFromBoundedEnum
)
import Data.Type.Equality
( (:~:) (..), testEquality )
( (:~:) (..)
, testEquality
)
import Data.Word
( Word32, Word8 )
( Word32
, Word8
)
import Fmt
( Buildable (..) )
( Buildable (..)
)
import GHC.Generics
( Generic )
( Generic
)
import GHC.Stack
( HasCallStack )
( HasCallStack
)
import GHC.TypeLits
( Symbol )
( Symbol
)
import Quiet
( Quiet (..) )
( Quiet (..)
)
import Safe
( readMay, toEnumMay )
( readMay
, toEnumMay
)
import Type.Reflection
( Typeable, typeRep )
( Typeable
, typeRep
)

import qualified Data.ByteString as BS
import qualified Data.Text as T
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ import Cardano.Crypto.Wallet
, unXPub
)
import Cardano.Mnemonic
( SomeMnemonic (..), entropyToBytes, mnemonicToEntropy )
( SomeMnemonic (..)
, entropyToBytes
, mnemonicToEntropy
)
import Cardano.Wallet.Address.Derivation
( Depth (..)
, DerivationType (..)
Expand All @@ -67,31 +70,45 @@ import Cardano.Wallet.Address.Derivation
, PaymentAddress (..)
)
import Cardano.Wallet.Primitive.NetworkId
( SNetworkId (..) )
( SNetworkId (..)
)
import Cardano.Wallet.Primitive.Passphrase
( Passphrase (..) )
( Passphrase (..)
)
import Cardano.Wallet.Primitive.Types.Address
( Address (..) )
( Address (..)
)
import Cardano.Wallet.Primitive.Types.ProtocolMagic
( magicSNetworkId )
( magicSNetworkId
)
import Control.DeepSeq
( NFData )
( NFData
)
import Control.Lens
( Lens, lens )
( Lens
, lens
)
import Crypto.Hash.Algorithms
( SHA512 (..) )
( SHA512 (..)
)
import Crypto.Hash.Extra
( blake2b256 )
( blake2b256
)
import Data.ByteArray
( ScrubbedBytes )
( ScrubbedBytes
)
import Data.ByteString
( ByteString )
( ByteString
)
import Data.Kind
( Type )
( Type
)
import Data.Proxy
( Proxy (..) )
( Proxy (..)
)
import GHC.Generics
( Generic )
( Generic
)

import qualified Cardano.Byron.Codec.Cbor as CBOR
import qualified Cardano.Wallet.Address.Derivation as W
Expand Down

0 comments on commit b534f20

Please sign in to comment.