Skip to content

Commit 3ef8ed1

Browse files
committed
Migrate to fourmolu.yaml
1 parent 29af4f3 commit 3ef8ed1

File tree

17 files changed

+323
-284
lines changed

17 files changed

+323
-284
lines changed

.github/workflows/haskell.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ jobs:
2222

2323
- name: Run fourmolu
2424
uses: haskell-actions/run-fourmolu@v11
25+
with:
26+
version: "latest"
2527

2628
- name: Cache Stack and binaries
2729
uses: actions/cache@v3

app/Main.hs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
module Main
2-
( main
3-
) where
1+
module Main (
2+
main,
3+
) where
44

55
import Control.Exception
66
import Core.Node (Node)
77
import Core.NodeCursor (newCursor)
8-
import qualified Data.ByteString.Lazy as BL
9-
( ByteString
10-
, readFile
11-
, toStrict
12-
, writeFile
13-
)
148
import Data.Functor (($>))
15-
import qualified Data.List as L (uncons)
16-
import qualified Data.Text as T (append, pack)
179
import Data.Text (Text)
18-
import qualified Data.Text.IO as TIO (putStrLn)
19-
import qualified Data.Text.Lazy as TL (fromStrict)
2010
import Data.Text.Lazy.Encoding (encodeUtf8)
21-
import GHC.IO.Exception (IOErrorType(NoSuchThing), IOException(IOError))
22-
import System.Environment (getArgs)
23-
import Transformation (transform)
24-
2511
import Formatting (RuleSet, formatNode, newRuleSet)
12+
import GHC.IO.Exception (IOErrorType (NoSuchThing), IOException (IOError))
2613
import Parsing.DSL (parseDSL)
2714
import Parsing.Jbeam (parseNodes)
15+
import System.Environment (getArgs)
16+
import Transformation (transform)
17+
18+
import Data.ByteString.Lazy qualified as BL (
19+
ByteString,
20+
readFile,
21+
toStrict,
22+
writeFile,
23+
)
24+
import Data.List qualified as L (uncons)
25+
import Data.Text qualified as T (append, pack)
26+
import Data.Text.IO qualified as TIO (putStrLn)
27+
import Data.Text.Lazy qualified as TL (fromStrict)
2828

2929
main :: IO ()
3030
main = do
@@ -54,8 +54,8 @@ readFormattingConfig = do
5454
Right rs -> pure rs
5555
Left err -> TIO.putStrLn err $> newRuleSet
5656

57-
ioErrorMsg ::
58-
[IOErrorType]
57+
ioErrorMsg
58+
:: [IOErrorType]
5959
-> Either IOException BL.ByteString
6060
-> Either Text BL.ByteString
6161
ioErrorMsg noerrs (Left (IOError _ ioe_type _ ioe_desc _ filename)) =

fourmolu.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
indentation: 2
2+
column-limit: 80
3+
import-export-style: diff-friendly
4+
import-grouping: by-qualified
5+
function-arrows: leading
6+
comma-style: leading
7+
indent-wheres: true
8+
let-style: inline
9+
in-style: right-align
10+
record-brace-space: true
11+
newlines-between-decls: 1
12+
haddock-style: multi-line
13+
haddock-style-module: multi-line
14+
single-constraint-parens: never
15+
single-deriving-parens: always
16+
sort-constraints: true
17+
sort-derived-classes: true
18+
sort-deriving-clauses: true
19+
trailing-section-operators: true
20+
fixities: []
21+
reexports: []
22+
local-modules: []

src/Core/Node.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module Core.Node
2-
( isCommentNode
3-
, Node(..)
4-
) where
1+
module Core.Node (
2+
isCommentNode,
3+
Node (..),
4+
) where
55

66
import Data.Scientific (Scientific)
77
import Data.Text (Text)
@@ -23,7 +23,7 @@ data Node
2323
| SinglelineComment Text
2424
| MultilineComment Text
2525
| Null
26-
deriving (Show, Eq)
26+
deriving (Eq, Show)
2727

2828
isCommentNode :: Node -> Bool
2929
isCommentNode (MultilineComment _) = True

src/Core/NodeCursor.hs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
module Core.NodeCursor
2-
( NodeCursor(..)
3-
, NodeBreadcrumb(..)
4-
, applyCrumb
5-
, applyObjCrumb
6-
, compareSB
7-
, comparePathAndCursor
8-
, newCursor
9-
) where
1+
module Core.NodeCursor (
2+
NodeCursor (..),
3+
NodeBreadcrumb (..),
4+
applyCrumb,
5+
applyObjCrumb,
6+
compareSB,
7+
comparePathAndCursor,
8+
newCursor,
9+
) where
10+
11+
import Core.Node (Node (..))
12+
import Data.Sequence (Seq (..))
13+
import Data.Text (Text)
1014

11-
import Core.Node (Node(..))
1215
import Core.NodePath qualified as NP
13-
import Data.Sequence (Seq(..))
1416
import Data.Sequence qualified as Seq (empty, null)
15-
import Data.Text (Text)
1617
import Data.Text qualified as T
1718

1819
data NodeBreadcrumb
@@ -23,8 +24,8 @@ instance Show NodeBreadcrumb where
2324
show (ArrayIndex i) = "[" <> show i <> "]"
2425
show (ObjectIndexAndKey (_, k)) = "." <> T.unpack k
2526

26-
newtype NodeCursor =
27-
NodeCursor (Seq NodeBreadcrumb)
27+
newtype NodeCursor
28+
= NodeCursor (Seq NodeBreadcrumb)
2829

2930
instance Show NodeCursor where
3031
show (NodeCursor (b :<| bs)) = show b <> show (NodeCursor bs)

src/Core/NodePath.hs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,34 @@
11
{-# LANGUAGE TypeFamilies #-}
22

3-
module Core.NodePath
4-
( NodePath(..)
5-
, NodeSelector(..)
6-
, queryNodes
7-
, select
8-
) where
9-
10-
import Core.Node qualified as N (Node(..))
11-
import Data.Sequence (Seq(..))
3+
module Core.NodePath (
4+
NodePath (..),
5+
NodeSelector (..),
6+
queryNodes,
7+
select,
8+
) where
9+
10+
import Data.Sequence (Seq (..))
1211
import Data.Text (Text)
13-
import Data.Text qualified as T
1412
import Data.Vector ((!?))
13+
import GHC.IsList (IsList (..))
14+
15+
import Core.Node qualified as N (Node (..))
16+
import Data.Text qualified as T
1517
import Data.Vector qualified as V
16-
import GHC.IsList (IsList(..))
1718

1819
data NodeSelector
1920
= ArrayIndex Int
2021
| ObjectKey Text
2122
| ObjectIndex Int
22-
deriving (Ord, Eq)
23+
deriving (Eq, Ord)
2324

2425
instance Show NodeSelector where
2526
show (ArrayIndex i) = "[" <> show i <> "]"
2627
show (ObjectKey k) = "." <> T.unpack k
2728
show (ObjectIndex k) = "." <> show k
2829

29-
newtype NodePath =
30-
NodePath (Seq NodeSelector)
30+
newtype NodePath
31+
= NodePath (Seq NodeSelector)
3132

3233
instance Show NodePath where
3334
show (NodePath (b :<| bs)) = show b <> show (NodePath bs)

src/Formatting.hs

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,44 @@
1-
module Formatting
2-
( formatNode
3-
, newRuleSet
4-
, RuleSet(..)
5-
) where
1+
module Formatting (
2+
formatNode,
3+
newRuleSet,
4+
RuleSet (..),
5+
) where
66

7-
import Core.Node (Node(..), isCommentNode)
8-
import Core.NodeCursor qualified as NC
7+
import Core.Node (Node (..), isCommentNode)
98
import Data.Bool (bool)
109
import Data.Char (isSpace)
11-
import Data.Scientific (FPFormat(Fixed), formatScientific)
12-
import Data.Text qualified as T
10+
import Data.Scientific (FPFormat (Fixed), formatScientific)
1311
import Data.Text (Text)
1412
import Data.Vector (Vector)
13+
import Formatting.Rules (
14+
RuleSet (..),
15+
applyPadLogic,
16+
findPropertiesForCursor,
17+
newRuleSet,
18+
noComplexNewLine,
19+
)
20+
21+
import Core.NodeCursor qualified as NC
22+
import Data.Text qualified as T
1523
import Data.Vector qualified as V (null, toList)
16-
import Formatting.Rules
17-
( RuleSet(..)
18-
, applyPadLogic
19-
, findPropertiesForCursor
20-
, newRuleSet
21-
, noComplexNewLine
22-
)
2324

24-
addDelimiters ::
25-
RuleSet -> Int -> NC.NodeCursor -> Bool -> [Text] -> [Node] -> [Text]
25+
addDelimiters
26+
:: RuleSet -> Int -> NC.NodeCursor -> Bool -> [Text] -> [Node] -> [Text]
2627
addDelimiters _ _ _ _ acc [] = acc
27-
addDelimiters rs index c complexChildren acc ns@(node:rest)
28+
addDelimiters rs index c complexChildren acc ns@(node : rest)
2829
| complexChildren && null acc =
29-
addDelimiters rs index c complexChildren ["\n"] ns
30+
addDelimiters rs index c complexChildren ["\n"] ns
3031
| isCommentNode node =
31-
addDelimiters
32-
rs
33-
newIndex
34-
c
35-
complexChildren
36-
(formatNode rs c node <> "\n" : acc)
37-
rest
32+
addDelimiters
33+
rs
34+
newIndex
35+
c
36+
complexChildren
37+
(formatNode rs c node <> "\n" : acc)
38+
rest
3839
| otherwise =
39-
let new_acc = T.concat [applyCrumbAndFormat, comma, space, newline] : acc
40-
in addDelimiters rs newIndex c complexChildren new_acc rest
40+
let new_acc = T.concat [applyCrumbAndFormat, comma, space, newline] : acc
41+
in addDelimiters rs newIndex c complexChildren new_acc rest
4142
where
4243
applyCrumbAndFormat =
4344
NC.applyCrumb (NC.ArrayIndex index) c (formatNode rs) node
@@ -64,8 +65,8 @@ indent s
6465
doFormatNode :: RuleSet -> NC.NodeCursor -> Vector Node -> Text
6566
doFormatNode rs cursor nodes =
6667
let formatted =
67-
reverse . addDelimiters rs 0 cursor complexChildren [] . V.toList
68-
$ nodes
68+
reverse . addDelimiters rs 0 cursor complexChildren [] . V.toList $
69+
nodes
6970
in if complexChildren
7071
then T.unlines . map indent . concatMap T.lines $ formatted
7172
else T.concat formatted
@@ -76,9 +77,9 @@ doFormatNode rs cursor nodes =
7677
padLogic :: (Node -> Text) -> Int -> Bool -> Node -> Text
7778
padLogic f padAmount padZeros n
7879
| not (isComplexNode n) =
79-
if padZeros && isNumberNode n
80-
then T.justifyLeft padAmount '0' $ f n
81-
else T.justifyRight padAmount ' ' $ f n
80+
if padZeros && isNumberNode n
81+
then T.justifyLeft padAmount '0' $ f n
82+
else T.justifyRight padAmount ' ' $ f n
8283
| otherwise = f n
8384

8485
formatScalarNode :: Node -> Text

0 commit comments

Comments
 (0)