Skip to content

Commit 5cbdf37

Browse files
Introduce purs-tidy formatter (#53)
* Add purs-tidy formatter * Run purs-tidy
1 parent 24a9a3b commit 5cbdf37

File tree

7 files changed

+93
-55
lines changed

7 files changed

+93
-55
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515

1616
- name: Set up 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
@@ -25,9 +27,9 @@ jobs:
2527
output
2628
2729
- name: Set up Node toolchain
28-
uses: actions/setup-node@v1
30+
uses: actions/setup-node@v2
2931
with:
30-
node-version: "12.x"
32+
node-version: "14.x"
3133

3234
- name: Cache NPM dependencies
3335
uses: actions/cache@v2
@@ -49,3 +51,6 @@ jobs:
4951

5052
- name: Run tests
5153
run: npm run test
54+
55+
- name: Check formatting
56+
run: purs-tidy check src test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
!.gitignore
33
!.github
44
!.editorconfig
5+
!.tidyrc.json
56
!.eslintrc.json
67

78
output

.tidyrc.json

Lines changed: 10 additions & 0 deletions
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+
}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
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 (#53 by @thomashoneyman)
1415
* Fixed readme bug where `jsonParser` was imported from `Data.Argonaut.Core` instead of `Data.Argonaut.Parser` (#50 by @flip111)
1516

1617
## [v6.0.0](https://github.com/purescript-contrib/purescript-argonaut-core/releases/tag/v6.0.0) - 2021-02-26

src/Data/Argonaut/Core.purs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ caseJson
7878
-> (String -> a)
7979
-> (Array Json -> a)
8080
-> (Object Json -> a)
81-
-> Json -> a
81+
-> Json
82+
-> a
8283
caseJson a b c d e f json = runFn7 _caseJson a b c d e f json
8384

8485
-- | A simpler version of `caseJson` which accepts a callback for when the
@@ -229,7 +230,7 @@ jsonEmptyObject = fromObject Obj.empty
229230

230231
-- | Constructs a `Json` array value containing only the provided value
231232
jsonSingletonArray :: Json -> Json
232-
jsonSingletonArray j = fromArray [j]
233+
jsonSingletonArray j = fromArray [ j ]
233234

234235
-- | Constructs a `Json` object value containing only the provided key and value
235236
jsonSingletonObject :: String -> Json -> Json
@@ -247,13 +248,13 @@ foreign import stringifyWithIndent :: Int -> Json -> String
247248
foreign import _caseJson
248249
:: forall z
249250
. Fn7
250-
(Unit -> z)
251-
(Boolean -> z)
252-
(Number -> z)
253-
(String -> z)
254-
(Array Json -> z)
255-
(Object Json -> z)
256-
Json
257-
z
251+
(Unit -> z)
252+
(Boolean -> z)
253+
(Number -> z)
254+
(String -> z)
255+
(Array Json -> z)
256+
(Object Json -> z)
257+
Json
258+
z
258259

259260
foreign import _compare :: Fn5 Ordering Ordering Ordering Json Json Ordering

src/Data/Argonaut/Gen.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ genJson = Gen.resize (min 5) $ Gen.sized genJson'
2323
| otherwise = genLeaf
2424

2525
genLeaf :: m J.Json
26-
genLeaf = Gen.oneOf $ pure J.jsonNull :| [genJBoolean, genJNumber, genJString]
26+
genLeaf = Gen.oneOf $ pure J.jsonNull :| [ genJBoolean, genJNumber, genJString ]
2727

2828
genJArray :: m J.Json
2929
genJArray = J.fromArray <$> Gen.unfoldable (defer \_ -> genJson)

test/Test/Main.purs

Lines changed: 62 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@ foldTest = do
4545

4646
foldFn :: Json -> String
4747
foldFn = caseJson
48-
(const "null")
49-
(const "boolean")
50-
(const "number")
51-
(const "string")
52-
(const "array")
53-
(const "object")
48+
(const "null")
49+
(const "boolean")
50+
(const "number")
51+
(const "string")
52+
(const "array")
53+
(const "object")
5454

5555
cases :: Array Json
5656
cases =
@@ -64,44 +64,63 @@ cases =
6464

6565
foldXXX :: Effect Unit
6666
foldXXX = do
67-
assert ((caseJsonNull "not null" (const "null") <$> cases) ==
68-
["null", "not null", "not null", "not null", "not null", "not null"] <?>
69-
"Error in caseJsonNull")
70-
assert ((caseJsonBoolean "not boolean" (const "boolean") <$> cases) ==
71-
["not boolean", "boolean", "not boolean", "not boolean", "not boolean", "not boolean"] <?>
72-
"Error in caseJsonBoolean")
73-
assert ((caseJsonNumber "not number" (const "number") <$> cases) ==
74-
["not number", "not number", "number", "not number", "not number", "not number"] <?>
75-
"Error in caseJsonNumber")
76-
77-
assert ((caseJsonString "not string" (const "string") <$> cases) ==
78-
["not string", "not string", "not string", "string", "not string", "not string"] <?>
79-
"Error in caseJsonString")
80-
81-
assert ((caseJsonArray "not array" (const "array") <$> cases) ==
82-
["not array", "not array", "not array", "not array", "array", "not array"] <?>
83-
"Error in caseJsonArray")
84-
assert ((caseJsonObject "not object" (const "object") <$> cases) ==
85-
["not object", "not object", "not object", "not object", "not object", "object"] <?>
86-
"Error in caseJsonObject")
87-
67+
assert
68+
( (caseJsonNull "not null" (const "null") <$> cases) ==
69+
[ "null", "not null", "not null", "not null", "not null", "not null" ] <?>
70+
"Error in caseJsonNull"
71+
)
72+
assert
73+
( (caseJsonBoolean "not boolean" (const "boolean") <$> cases) ==
74+
[ "not boolean", "boolean", "not boolean", "not boolean", "not boolean", "not boolean" ] <?>
75+
"Error in caseJsonBoolean"
76+
)
77+
assert
78+
( (caseJsonNumber "not number" (const "number") <$> cases) ==
79+
[ "not number", "not number", "number", "not number", "not number", "not number" ] <?>
80+
"Error in caseJsonNumber"
81+
)
82+
83+
assert
84+
( (caseJsonString "not string" (const "string") <$> cases) ==
85+
[ "not string", "not string", "not string", "string", "not string", "not string" ] <?>
86+
"Error in caseJsonString"
87+
)
88+
89+
assert
90+
( (caseJsonArray "not array" (const "array") <$> cases) ==
91+
[ "not array", "not array", "not array", "not array", "array", "not array" ] <?>
92+
"Error in caseJsonArray"
93+
)
94+
assert
95+
( (caseJsonObject "not object" (const "object") <$> cases) ==
96+
[ "not object", "not object", "not object", "not object", "not object", "object" ] <?>
97+
"Error in caseJsonObject"
98+
)
8899

89100
fromTest :: Effect Unit
90101
fromTest = do
91102
assert ((caseJsonNull false (const true) jsonNull) <?> "Error in fromNull")
92103
quickCheck (\bool -> caseJsonBoolean Nothing Just (fromBoolean bool) == Just bool <?> "Error in fromBoolean")
93104
quickCheck (\num -> caseJsonNumber Nothing Just (fromNumber num) == Just num <?> "Error in fromNumber")
94105
quickCheck (\str -> caseJsonString Nothing Just (fromString str) == Just str <?> "Error in fromString")
95-
quickCheck (\num ->
96-
let arr :: Array Json
97-
arr = A.singleton (fromNumber num)
98-
in (caseJsonArray Nothing Just (fromArray arr) == Just arr)
99-
<?> "Error in fromArray")
100-
quickCheck (\(Tuple str num) ->
101-
let sm :: Obj.Object Json
102-
sm = Obj.singleton str (fromNumber num)
103-
in (caseJsonObject Nothing Just (fromObject sm) == Just sm)
104-
<?> "Error in fromObject")
106+
quickCheck
107+
( \num ->
108+
let
109+
arr :: Array Json
110+
arr = A.singleton (fromNumber num)
111+
in
112+
(caseJsonArray Nothing Just (fromArray arr) == Just arr)
113+
<?> "Error in fromArray"
114+
)
115+
quickCheck
116+
( \(Tuple str num) ->
117+
let
118+
sm :: Obj.Object Json
119+
sm = Obj.singleton str (fromNumber num)
120+
in
121+
(caseJsonObject Nothing Just (fromObject sm) == Just sm)
122+
<?> "Error in fromObject"
123+
)
105124

106125
toTest :: Effect Unit
107126
toTest = do
@@ -114,10 +133,11 @@ toTest = do
114133
where
115134
assertion :: forall a. (Eq a) => (Json -> Maybe a) -> Json -> String -> Result
116135
assertion fn j msg =
117-
let forCases = A.catMaybes (fn <$> cases)
118-
exact = A.singleton $ unsafePartial fromJust $ fn j
119-
in forCases == exact <?> msg
120-
136+
let
137+
forCases = A.catMaybes (fn <$> cases)
138+
exact = A.singleton $ unsafePartial fromJust $ fn j
139+
in
140+
forCases == exact <?> msg
121141

122142
parserTest :: Effect Unit
123143
parserTest = do
@@ -128,7 +148,7 @@ parserTest = do
128148
roundtripTest = do
129149
json <- Gen.resize (const 5) genJson
130150
let parsed = jsonParser (stringify json)
131-
pure $ parsed == Right json <?> show (stringify <$> parsed) <> " /= " <> stringify json
151+
pure $ parsed == Right json <?> show (stringify <$> parsed) <> " /= " <> stringify json
132152

133153
assert :: forall prop. Testable prop => prop -> Effect Unit
134154
assert = quickCheck' 1

0 commit comments

Comments
 (0)