Skip to content

Commit

Permalink
Add fourmolu to CI and apply it to the project (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raveline authored Oct 1, 2024
1 parent 573a865 commit d83fb05
Show file tree
Hide file tree
Showing 27 changed files with 3,553 additions and 2,584 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Fourmolu
on: push
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: haskell-actions/run-fourmolu@v10
with:
version: "0.15.0.0"

15 changes: 10 additions & 5 deletions .github/workflows/haskell-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ jobs:
strategy:
matrix:
include:
- compiler: ghc-9.10.1
compilerKind: ghc
compilerVersion: 9.10.1
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.8.2
compilerKind: ghc
compilerVersion: 9.8.2
setup-method: ghcup
allow-failure: false
- compiler: ghc-9.6.2
compilerKind: ghc
compilerVersion: 9.6.2
Expand All @@ -63,11 +73,6 @@ jobs:
compilerVersion: 8.10.7
setup-method: ghcup
allow-failure: false
- compiler: ghc-8.8.4
compilerKind: ghc
compilerVersion: 8.8.4
setup-method: ghcup
allow-failure: false
fail-fast: false
steps:
- name: apt
Expand Down
2 changes: 0 additions & 2 deletions Setup.hs

This file was deleted.

260 changes: 216 additions & 44 deletions benchmark/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,71 @@ import Test.Tasty.Bench
import Database.PostgreSQL.PQTypes.Deriving

main :: IO ()
main = defaultMain
[ bgroup "enum"
[ bench "encode" $ nf (encodeEnum @T) T42
, bench "decode" $ nf (decodeEnum @T) 42
main =
defaultMain
[ bgroup
"enum"
[ bench "encode" $ nf (encodeEnum @T) T42
, bench "decode" $ nf (decodeEnum @T) 42
]
, bgroup
"enum-text"
[ bench "encode" $ nf (encodeEnumAsText @S) S42
, bench "decode" $ nf (decodeEnumAsText @S) "text_42"
]
]
, bgroup "enum-text"
[ bench "encode" $ nf (encodeEnumAsText @S) S42
, bench "decode" $ nf (decodeEnumAsText @S) "text_42"
]
]

data T = T01 | T02 | T03 | T04 | T05 | T06 | T07 | T08 | T09 | T10
| T11 | T12 | T13 | T14 | T15 | T16 | T17 | T18 | T19 | T20
| T21 | T22 | T23 | T24 | T25 | T26 | T27 | T28 | T29 | T30
| T31 | T32 | T33 | T34 | T35 | T36 | T37 | T38 | T39 | T40
| T41 | T42 | T43 | T44 | T45 | T46 | T47 | T48 | T49 | T50
data T
= T01
| T02
| T03
| T04
| T05
| T06
| T07
| T08
| T09
| T10
| T11
| T12
| T13
| T14
| T15
| T16
| T17
| T18
| T19
| T20
| T21
| T22
| T23
| T24
| T25
| T26
| T27
| T28
| T29
| T30
| T31
| T32
| T33
| T34
| T35
| T36
| T37
| T38
| T39
| T40
| T41
| T42
| T43
| T44
| T45
| T46
| T47
| T48
| T49
| T50
deriving (Eq, Show, Enum, Bounded)

instance NFData T where
Expand All @@ -33,26 +82,112 @@ instance NFData T where
-- >>> isInjective (encodeEnum @T)
-- True
instance EnumEncoding T where
type EnumBase T = Int16
encodeEnum = \case
T01 -> 1; T02 -> 2; T03 -> 3; T04 -> 4; T05 -> 5
T06 -> 6; T07 -> 7; T08 -> 8; T09 -> 9; T10 -> 10
T11 -> 11; T12 -> 12; T13 -> 13; T14 -> 14; T15 -> 15
T16 -> 16; T17 -> 17; T18 -> 18; T19 -> 19; T20 -> 20
T21 -> 21; T22 -> 22; T23 -> 23; T24 -> 24; T25 -> 25
T26 -> 26; T27 -> 27; T28 -> 28; T29 -> 29; T30 -> 30
T31 -> 31; T32 -> 32; T33 -> 33; T34 -> 34; T35 -> 35
T36 -> 36; T37 -> 37; T38 -> 38; T39 -> 39; T40 -> 40
T41 -> 41; T42 -> 42; T43 -> 43; T44 -> 44; T45 -> 45
T46 -> 46; T47 -> 47; T48 -> 48; T49 -> 49; T50 -> 50
type EnumBase T = Int16
encodeEnum = \case
T01 -> 1
T02 -> 2
T03 -> 3
T04 -> 4
T05 -> 5
T06 -> 6
T07 -> 7
T08 -> 8
T09 -> 9
T10 -> 10
T11 -> 11
T12 -> 12
T13 -> 13
T14 -> 14
T15 -> 15
T16 -> 16
T17 -> 17
T18 -> 18
T19 -> 19
T20 -> 20
T21 -> 21
T22 -> 22
T23 -> 23
T24 -> 24
T25 -> 25
T26 -> 26
T27 -> 27
T28 -> 28
T29 -> 29
T30 -> 30
T31 -> 31
T32 -> 32
T33 -> 33
T34 -> 34
T35 -> 35
T36 -> 36
T37 -> 37
T38 -> 38
T39 -> 39
T40 -> 40
T41 -> 41
T42 -> 42
T43 -> 43
T44 -> 44
T45 -> 45
T46 -> 46
T47 -> 47
T48 -> 48
T49 -> 49
T50 -> 50

----------------------------------------

data S = S01 | S02 | S03 | S04 | S05 | S06 | S07 | S08 | S09 | S10
| S11 | S12 | S13 | S14 | S15 | S16 | S17 | S18 | S19 | S20
| S21 | S22 | S23 | S24 | S25 | S26 | S27 | S28 | S29 | S30
| S31 | S32 | S33 | S34 | S35 | S36 | S37 | S38 | S39 | S40
| S41 | S42 | S43 | S44 | S45 | S46 | S47 | S48 | S49 | S50
data S
= S01
| S02
| S03
| S04
| S05
| S06
| S07
| S08
| S09
| S10
| S11
| S12
| S13
| S14
| S15
| S16
| S17
| S18
| S19
| S20
| S21
| S22
| S23
| S24
| S25
| S26
| S27
| S28
| S29
| S30
| S31
| S32
| S33
| S34
| S35
| S36
| S37
| S38
| S39
| S40
| S41
| S42
| S43
| S44
| S45
| S46
| S47
| S48
| S49
| S50
deriving (Eq, Show, Enum, Bounded)

instance NFData S where
Expand All @@ -64,16 +199,53 @@ instance NFData S where
-- True
instance EnumAsTextEncoding S where
encodeEnumAsText = \case
S01 -> "text_01"; S02 -> "text_02"; S03 -> "text_03"; S04 -> "text_04"
S05 -> "text_05"; S06 -> "text_06"; S07 -> "text_07"; S08 -> "text_08"
S09 -> "text_09"; S10 -> "text_10"; S11 -> "text_11"; S12 -> "text_12"
S13 -> "text_13"; S14 -> "text_14"; S15 -> "text_15"; S16 -> "text_16"
S17 -> "text_17"; S18 -> "text_18"; S19 -> "text_19"; S20 -> "text_20"
S21 -> "text_21"; S22 -> "text_22"; S23 -> "text_23"; S24 -> "text_24"
S25 -> "text_25"; S26 -> "text_26"; S27 -> "text_27"; S28 -> "text_28"
S29 -> "text_29"; S30 -> "text_30"; S31 -> "text_31"; S32 -> "text_32"
S33 -> "text_33"; S34 -> "text_34"; S35 -> "text_35"; S36 -> "text_36"
S37 -> "text_37"; S38 -> "text_38"; S39 -> "text_39"; S40 -> "text_40"
S41 -> "text_41"; S42 -> "text_42"; S43 -> "text_43"; S44 -> "text_44"
S45 -> "text_45"; S46 -> "text_46"; S47 -> "text_47"; S48 -> "text_48"
S49 -> "text_49"; S50 -> "text_50";
S01 -> "text_01"
S02 -> "text_02"
S03 -> "text_03"
S04 -> "text_04"
S05 -> "text_05"
S06 -> "text_06"
S07 -> "text_07"
S08 -> "text_08"
S09 -> "text_09"
S10 -> "text_10"
S11 -> "text_11"
S12 -> "text_12"
S13 -> "text_13"
S14 -> "text_14"
S15 -> "text_15"
S16 -> "text_16"
S17 -> "text_17"
S18 -> "text_18"
S19 -> "text_19"
S20 -> "text_20"
S21 -> "text_21"
S22 -> "text_22"
S23 -> "text_23"
S24 -> "text_24"
S25 -> "text_25"
S26 -> "text_26"
S27 -> "text_27"
S28 -> "text_28"
S29 -> "text_29"
S30 -> "text_30"
S31 -> "text_31"
S32 -> "text_32"
S33 -> "text_33"
S34 -> "text_34"
S35 -> "text_35"
S36 -> "text_36"
S37 -> "text_37"
S38 -> "text_38"
S39 -> "text_39"
S40 -> "text_40"
S41 -> "text_41"
S42 -> "text_42"
S43 -> "text_43"
S44 -> "text_44"
S45 -> "text_45"
S46 -> "text_46"
S47 -> "text_47"
S48 -> "text_48"
S49 -> "text_49"
S50 -> "text_50"
53 changes: 53 additions & 0 deletions fourmolu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Number of spaces per indentation step
indentation: 2

# Max line length for automatic line breaking
column-limit: none

# Styling of arrows in type signatures (choices: trailing, leading, or leading-args)
function-arrows: leading

# How to place commas in multi-line lists, records, etc. (choices: leading or trailing)
comma-style: leading

# Styling of import/export lists (choices: leading, trailing, or diff-friendly)
import-export-style: leading

# Whether to full-indent or half-indent 'where' bindings past the preceding body
indent-wheres: true

# Whether to leave a space before an opening record brace
record-brace-space: true

# Number of spaces between top-level declarations
newlines-between-decls: 1

# How to print Haddock comments (choices: single-line, multi-line, or multi-line-compact)
haddock-style: single-line

# How to print module docstring
haddock-style-module: null

# Styling of let blocks (choices: auto, inline, newline, or mixed)
let-style: inline

# How to align the 'in' keyword with respect to the 'let' keyword (choices: left-align, right-align, or no-space)
in-style: no-space

# Whether to put parentheses around a single constraint (choices: auto, always, or never)
single-constraint-parens: never

# Whether to put parentheses around a single deriving class (choices: auto, always, or never)
single-deriving-parens: always

# Output Unicode syntax (choices: detect, always, or never)
unicode: never

# Give the programmer more choice on where to insert blank lines
respectful: true

# Fixity information for operators
fixities: []

# Module reexports Fourmolu should know about
reexports: []
Loading

0 comments on commit d83fb05

Please sign in to comment.