Skip to content

Commit 80a4398

Browse files
authored
Merge pull request #55 from input-output-hk/fourmolu-ci
Switched to fourmolu, added a CI step to check formatting
2 parents 6920b7e + 8272a62 commit 80a4398

File tree

20 files changed

+742
-671
lines changed

20 files changed

+742
-671
lines changed

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,28 @@ jobs:
5656
- name: Run tests
5757
run: |
5858
cabal test all
59+
60+
fourmolu:
61+
runs-on: ubuntu-latest
62+
63+
defaults:
64+
run:
65+
shell: bash
66+
67+
strategy:
68+
fail-fast: false
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Install fourmolu
74+
run: |
75+
FOURMOLU_VERSION="0.16.2.0"
76+
mkdir -p "$HOME/.local/bin"
77+
curl -sL "https://github.com/fourmolu/fourmolu/releases/download/v${FOURMOLU_VERSION}/fourmolu-${FOURMOLU_VERSION}-linux-x86_64" -o "$HOME/.local/bin/fourmolu"
78+
chmod a+x "$HOME/.local/bin/fourmolu"
79+
echo "$HOME/.local/bin" >> $GITHUB_PATH
80+
81+
- name: Run fourmolu
82+
run: ./scripts/fourmolize.sh
83+

bin/Main.hs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
module Main (main) where
44

55
import Codec.CBOR.Cuddle.CBOR.Gen (generateCBORTerm)
6-
import Codec.CBOR.Cuddle.CDDL (Name (..))
7-
import Codec.CBOR.Cuddle.CDDL.Resolve
8-
( fullResolveCDDL,
9-
)
6+
import Codec.CBOR.Cuddle.CDDL (Name (..), sortCDDL)
7+
import Codec.CBOR.Cuddle.CDDL.Resolve (
8+
fullResolveCDDL,
9+
)
1010
import Codec.CBOR.Cuddle.Parser (pCDDL)
1111
import Codec.CBOR.Cuddle.Pretty ()
1212
import Codec.CBOR.FlatTerm (toFlatTerm)
@@ -22,7 +22,6 @@ import System.Exit (exitFailure, exitSuccess)
2222
import System.IO (hPutStrLn, stderr)
2323
import System.Random (getStdGen)
2424
import Text.Megaparsec (ParseErrorBundle, Parsec, errorBundlePretty, runParser)
25-
import Codec.CBOR.Cuddle.CDDL (sortCDDL)
2625

2726
data Opts = Opts Command String
2827

@@ -47,8 +46,8 @@ pCBOROutputFormat = eitherReader $ \case
4746
s -> Left s
4847

4948
data GenOpts = GenOpts
50-
{ itemName :: T.Text,
51-
outputFormat :: CBOROutputFormat
49+
{ itemName :: T.Text
50+
, outputFormat :: CBOROutputFormat
5251
}
5352

5453
pGenOpts :: Parser GenOpts
@@ -86,23 +85,20 @@ opts =
8685
( command
8786
"format"
8887
( info
89-
( Format <$> pFormatOpts)
90-
( progDesc "Format the provided CDDL file"
91-
)
88+
(Format <$> pFormatOpts)
89+
(progDesc "Format the provided CDDL file")
9290
)
9391
<> command
9492
"validate"
9593
( info
9694
(pure Validate)
97-
( progDesc "Validate the provided CDDL file"
98-
)
95+
(progDesc "Validate the provided CDDL file")
9996
)
10097
<> command
10198
"gen"
10299
( info
103100
(GenerateCBOR <$> pGenOpts)
104-
( progDesc "Generate a CBOR term matching the schema"
105-
)
101+
(progDesc "Generate a CBOR term matching the schema")
106102
)
107103
)
108104
<*> argument str (metavar "CDDL_FILE")
@@ -126,8 +122,9 @@ run (Opts cmd cddlFile) = do
126122
putStrLnErr $ errorBundlePretty err
127123
exitFailure
128124
Right res -> case cmd of
129-
Format fOpts -> let defs = if sort fOpts then sortCDDL res else res in
130-
putDocW 80 $ pretty defs
125+
Format fOpts ->
126+
let defs = if sort fOpts then sortCDDL res else res
127+
in putDocW 80 $ pretty defs
131128
Validate -> case fullResolveCDDL res of
132129
Left err -> putStrLnErr (show err) >> exitFailure
133130
Right _ -> exitSuccess

0 commit comments

Comments
 (0)