Skip to content

Commit 14b88c4

Browse files
Introduce purs-tidy formatter (#104)
* Add purs-tidy formatter * Run purs-tidy
1 parent 2f23841 commit 14b88c4

File tree

9 files changed

+72
-54
lines changed

9 files changed

+72
-54
lines changed

Diff for: .github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515

1616
- name: Set up a PureScript toolchain
1717
uses: purescript-contrib/setup-purescript@main
18+
with:
19+
purs-tidy: "latest"
1820

1921
- name: Cache PureScript dependencies
2022
uses: actions/cache@v2
@@ -32,3 +34,6 @@ jobs:
3234

3335
- name: Run tests
3436
run: spago test --no-install
37+
38+
- name: Check formatting
39+
run: purs-tidy check src test

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
!.gitignore
33
!.github
44
!.editorconfig
5+
!.tidyrc.json
56

67
output
78
generated-docs

Diff for: .tidyrc.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"importSort": "source",
3+
"importWrap": "source",
4+
"indent": 2,
5+
"operatorsFile": null,
6+
"ribbon": 1,
7+
"typeArrowPlacement": "first",
8+
"unicode": "never",
9+
"width": null
10+
}

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ New features:
1111
Bugfixes:
1212

1313
Other improvements:
14+
- Added `purs-tidy` formatter (#104 by @thomashoneyman)
1415

1516
## [v8.1.0](https://github.com/purescript-contrib/purescript-argonaut-codecs/releases/tag/v8.1.0) - 2021-04-09
1617

Diff for: src/Data/Argonaut/Decode/Class.purs

+19-19
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,11 @@ instance decodeMap :: (Ord a, DecodeJson a, DecodeJson b) => DecodeJson (M.Map a
9494
instance decodeVoid :: DecodeJson Void where
9595
decodeJson = decodeVoid
9696

97-
instance decodeRecord
98-
:: ( GDecodeJson row list
99-
, RL.RowToList row list
100-
)
101-
=> DecodeJson (Record row) where
97+
instance decodeRecord ::
98+
( GDecodeJson row list
99+
, RL.RowToList row list
100+
) =>
101+
DecodeJson (Record row) where
102102
decodeJson json =
103103
case toObject json of
104104
Just object -> gDecodeJson object (Proxy :: Proxy list)
@@ -110,14 +110,14 @@ class GDecodeJson (row :: Row Type) (list :: RL.RowList Type) | list -> row wher
110110
instance gDecodeJsonNil :: GDecodeJson () RL.Nil where
111111
gDecodeJson _ _ = Right {}
112112

113-
instance gDecodeJsonCons
114-
:: ( DecodeJsonField value
115-
, GDecodeJson rowTail tail
116-
, IsSymbol field
117-
, Row.Cons field value rowTail row
118-
, Row.Lacks field rowTail
119-
)
120-
=> GDecodeJson row (RL.Cons field value tail) where
113+
instance gDecodeJsonCons ::
114+
( DecodeJsonField value
115+
, GDecodeJson rowTail tail
116+
, IsSymbol field
117+
, Row.Cons field value rowTail row
118+
, Row.Lacks field rowTail
119+
) =>
120+
GDecodeJson row (RL.Cons field value tail) where
121121
gDecodeJson object _ = do
122122
let
123123
_field = Proxy :: Proxy field
@@ -136,13 +136,13 @@ instance gDecodeJsonCons
136136
class DecodeJsonField a where
137137
decodeJsonField :: Maybe Json -> Maybe (Either JsonDecodeError a)
138138

139-
instance decodeFieldMaybe
140-
:: DecodeJson a
141-
=> DecodeJsonField (Maybe a) where
139+
instance decodeFieldMaybe ::
140+
DecodeJson a =>
141+
DecodeJsonField (Maybe a) where
142142
decodeJsonField Nothing = Just $ Right Nothing
143143
decodeJsonField (Just j) = Just $ decodeJson j
144144

145-
else instance decodeFieldId
146-
:: DecodeJson a
147-
=> DecodeJsonField a where
145+
else instance decodeFieldId ::
146+
DecodeJson a =>
147+
DecodeJsonField a where
148148
decodeJsonField j = decodeJson <$> j

Diff for: src/Data/Argonaut/Decode/Decoders.purs

+9-9
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ decodeTuple decoderA decoderB json = decodeArray Right json >>= f
5353
where
5454
f :: Array Json -> Either JsonDecodeError (Tuple a b)
5555
f = case _ of
56-
[a, b] -> Tuple <$> decoderA a <*> decoderB b
56+
[ a, b ] -> Tuple <$> decoderA a <*> decoderB b
5757
_ -> Left $ TypeMismatch "Tuple"
5858

5959
decodeEither
@@ -100,8 +100,8 @@ decodeNonEmpty_Array decoder =
100100
lmap (Named "NonEmpty Array")
101101
<<< traverse decoder
102102
<=< map (\x -> x.head :| x.tail)
103-
<<< note (TypeMismatch "NonEmpty Array")
104-
<<< Arr.uncons
103+
<<< note (TypeMismatch "NonEmpty Array")
104+
<<< Arr.uncons
105105
<=< decodeJArray
106106

107107
decodeNonEmptyArray
@@ -113,8 +113,8 @@ decodeNonEmptyArray decoder =
113113
lmap (Named "NonEmptyArray")
114114
<<< traverse decoder
115115
<=< map (\x -> NEA.cons' x.head x.tail)
116-
<<< note (TypeMismatch "NonEmptyArray")
117-
<<< Arr.uncons
116+
<<< note (TypeMismatch "NonEmptyArray")
117+
<<< Arr.uncons
118118
<=< decodeJArray
119119

120120
decodeNonEmpty_List
@@ -126,8 +126,8 @@ decodeNonEmpty_List decoder =
126126
lmap (Named "NonEmpty List")
127127
<<< traverse decoder
128128
<=< map (\x -> x.head :| x.tail)
129-
<<< note (TypeMismatch "NonEmpty List")
130-
<<< L.uncons
129+
<<< note (TypeMismatch "NonEmpty List")
130+
<<< L.uncons
131131
<=< map (map fromFoldable) decodeJArray
132132

133133
decodeNonEmptyList
@@ -139,8 +139,8 @@ decodeNonEmptyList decoder =
139139
lmap (Named "NonEmptyList")
140140
<<< traverse decoder
141141
<=< map (\x -> NEL.cons' x.head x.tail)
142-
<<< note (TypeMismatch "NonEmptyList")
143-
<<< L.uncons
142+
<<< note (TypeMismatch "NonEmptyList")
143+
<<< L.uncons
144144
<=< map (map fromFoldable) decodeJArray
145145

146146
decodeCodePoint :: Json -> Either JsonDecodeError CodePoint

Diff for: src/Data/Argonaut/Encode/Class.purs

+12-12
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ instance encodeMap :: (Ord a, EncodeJson a, EncodeJson b) => EncodeJson (M.Map a
9595
instance encodeVoid :: EncodeJson Void where
9696
encodeJson = encodeVoid
9797

98-
instance encodeRecord
99-
:: ( GEncodeJson row list
100-
, RL.RowToList row list
101-
)
102-
=> EncodeJson (Record row) where
98+
instance encodeRecord ::
99+
( GEncodeJson row list
100+
, RL.RowToList row list
101+
) =>
102+
EncodeJson (Record row) where
103103
encodeJson rec = fromObject $ gEncodeJson rec (Proxy :: Proxy list)
104104

105105
class GEncodeJson (row :: Row Type) (list :: RL.RowList Type) where
@@ -108,13 +108,13 @@ class GEncodeJson (row :: Row Type) (list :: RL.RowList Type) where
108108
instance gEncodeJsonNil :: GEncodeJson row RL.Nil where
109109
gEncodeJson _ _ = FO.empty
110110

111-
instance gEncodeJsonCons
112-
:: ( EncodeJson value
113-
, GEncodeJson row tail
114-
, IsSymbol field
115-
, Row.Cons field value tail' row
116-
)
117-
=> GEncodeJson row (RL.Cons field value tail) where
111+
instance gEncodeJsonCons ::
112+
( EncodeJson value
113+
, GEncodeJson row tail
114+
, IsSymbol field
115+
, Row.Cons field value tail' row
116+
) =>
117+
GEncodeJson row (RL.Cons field value tail) where
118118
gEncodeJson row _ = do
119119
let _field = Proxy :: Proxy field
120120
FO.insert

Diff for: src/Data/Argonaut/Encode/Encoders.purs

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ encodeMaybe encoder = case _ of
3333
Just a -> encoder a
3434

3535
encodeTuple :: forall a b. (a -> Json) -> (b -> Json) -> Tuple a b -> Json
36-
encodeTuple encoderA encoderB (Tuple a b) = fromArray [encoderA a, encoderB b]
36+
encodeTuple encoderA encoderB (Tuple a b) = fromArray [ encoderA a, encoderB b ]
3737

38-
encodeEither :: forall a b . (a -> Json) -> (b -> Json) -> Either a b -> Json
38+
encodeEither :: forall a b. (a -> Json) -> (b -> Json) -> Either a b -> Json
3939
encodeEither encoderA encoderB = either (obj encoderA "Left") (obj encoderB "Right")
4040
where
4141
obj :: forall c. (c -> Json) -> String -> c -> Json

Diff for: test/Test/Main.purs

+13-12
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,10 @@ combinatorsCheck = do
206206
where
207207
go :: FO.Object Json -> Boolean
208208
go object =
209-
let keys = FO.keys object
210-
in foldl (\ok key -> ok && isJust (FO.lookup key object)) true keys
209+
let
210+
keys = FO.keys object
211+
in
212+
foldl (\ok key -> ok && isJust (FO.lookup key object)) true keys
211213

212214
eitherCheck :: Test
213215
eitherCheck = do
@@ -287,7 +289,7 @@ manualRecordDecode = do
287289
testBazCases = do
288290
test "Missing 'baz' key should decode to FooNested" do
289291
case decodeJson fooNestedBarJson of
290-
Right (FooNested { bar: Just [1], baz: false }) -> pure unit
292+
Right (FooNested { bar: Just [ 1 ], baz: false }) -> pure unit
291293
_ -> failure ("Failed to properly decode JSON string: " <> stringify fooNestedBarJson)
292294

293295
test "Null 'baz' key should fail to decode to FooNested" do
@@ -297,24 +299,24 @@ manualRecordDecode = do
297299

298300
test "Missing 'baz' key should decode to FooNested'" do
299301
case decodeJson fooNestedBarJson of
300-
Right (FooNested' { bar: Just [1], baz: false }) -> pure unit
302+
Right (FooNested' { bar: Just [ 1 ], baz: false }) -> pure unit
301303
_ -> failure ("Failed to properly decode JSON string: " <> stringify fooNestedBarJson)
302304

303305
test "Null 'baz' key should decode to FooNested'" do
304306
case decodeJson fooNestedBarJsonNull of
305-
Right (FooNested' { bar: Just [1], baz: false }) -> pure unit
307+
Right (FooNested' { bar: Just [ 1 ], baz: false }) -> pure unit
306308
_ -> failure ("Failed to properly decode JSON string: " <> stringify fooNestedBarJsonNull)
307309

308310
testFullCases :: Test
309311
testFullCases = do
310312
test "Json should decode to FooNested" do
311313
case decodeJson fooNestedFullJson of
312-
Right (FooNested { bar: Just [1], baz: true }) -> pure unit
314+
Right (FooNested { bar: Just [ 1 ], baz: true }) -> pure unit
313315
_ -> failure ("Failed to properly decode JSON string: " <> stringify fooNestedFullJson)
314316

315317
test "Json should decode to FooNested'" do
316318
case decodeJson fooNestedFullJson of
317-
Right (FooNested { bar: Just [1], baz: true }) -> pure unit
319+
Right (FooNested { bar: Just [ 1 ], baz: true }) -> pure unit
318320
_ -> failure ("Failed to properly decode JSON string: " <> stringify fooNestedFullJson)
319321

320322
test "Test that decoding custom record is pure unitful" do
@@ -338,17 +340,16 @@ nonEmptyCheck = do
338340
Left err ->
339341
false <?> printJsonDecodeError err
340342

341-
342343
test "Test EncodeJson/DecodeJson on NonEmptyString" do
343344
quickCheck \(x :: NonEmptyString) ->
344345
case decodeJson (encodeJson x) of
345346
Right decoded ->
346347
decoded == x
347348
<?>
348-
( " x = "
349-
<> NonEmptyString.toString x
350-
<> ", decoded = "
351-
<> NonEmptyString.toString decoded
349+
( " x = "
350+
<> NonEmptyString.toString x
351+
<> ", decoded = "
352+
<> NonEmptyString.toString decoded
352353
)
353354
Left err ->
354355
false <?> printJsonDecodeError err

0 commit comments

Comments
 (0)