Skip to content

Commit 5bf454c

Browse files
Introduce purs-tidy formatter (#167)
1 parent 2c2e6e6 commit 5bf454c

File tree

6 files changed

+52
-29
lines changed

6 files changed

+52
-29
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 (#167 by @thomashoneyman)
1415

1516
## [v12.0.0](https://github.com/purescript-contrib/purescript-affjax/releases/tag/v12.0.0) - 2021-02-26
1617

src/Affjax.purs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
module Affjax
2-
( Request, defaultRequest
2+
( Request
3+
, defaultRequest
34
, Response
45
, Error(..)
56
, printError
67
, URL
78
, request
89
, get
9-
, post, post_
10-
, put, put_
11-
, delete, delete_
12-
, patch, patch_
10+
, post
11+
, post_
12+
, put
13+
, put_
14+
, delete
15+
, delete_
16+
, patch
17+
, patch_
1318
) where
1419

1520
import Prelude
@@ -193,12 +198,14 @@ request req =
193198
case runExcept (fromResponse res.body) of
194199
Left err -> Left (ResponseBodyError (NEL.head err) res)
195200
Right body -> Right (res { body = body })
196-
Left err ->
201+
Left err -> Left do
197202
let message = Exn.message err
198-
in Left $
199-
if message == timeoutErrorMessageIdent then TimeoutError
200-
else if message == requestFailedMessageIdent then RequestFailedError
201-
else XHROtherError err
203+
if message == timeoutErrorMessageIdent then
204+
TimeoutError
205+
else if message == requestFailedMessageIdent then
206+
RequestFailedError
207+
else
208+
XHROtherError err
202209

203210
ajaxRequest :: Nullable Foreign -> AjaxRequest a
204211
ajaxRequest =
@@ -233,9 +240,8 @@ request req =
233240

234241
headers :: Maybe RequestBody.RequestBody -> Array RequestHeader
235242
headers reqContent =
236-
addHeader (ContentType <$> (RequestBody.toMediaType =<< reqContent)) $
237-
addHeader (Accept <$> ResponseFormat.toMediaType req.responseFormat)
238-
req.headers
243+
addHeader (ContentType <$> (RequestBody.toMediaType =<< reqContent))
244+
$ addHeader (Accept <$> ResponseFormat.toMediaType req.responseFormat) req.headers
239245

240246
timeoutErrorMessageIdent :: String
241247
timeoutErrorMessageIdent = "AffjaxTimeoutErrorMessageIdent"
@@ -257,9 +263,10 @@ request req =
257263
fromResponse = case req.responseFormat of
258264
ResponseFormat.ArrayBuffer _ -> unsafeReadTagged "ArrayBuffer"
259265
ResponseFormat.Blob _ -> unsafeReadTagged "Blob"
260-
ResponseFormat.Document _ -> \x → unsafeReadTagged "Document" x
261-
<|> unsafeReadTagged "XMLDocument" x
262-
<|> unsafeReadTagged "HTMLDocument" x
266+
ResponseFormat.Document _ -> \x ->
267+
unsafeReadTagged "Document" x
268+
<|> unsafeReadTagged "XMLDocument" x
269+
<|> unsafeReadTagged "HTMLDocument" x
263270
ResponseFormat.Json coe -> coe <<< parseJSON <=< unsafeReadTagged "String"
264271
ResponseFormat.String _ -> unsafeReadTagged "String"
265272
ResponseFormat.Ignore coe -> const $ coe (pure unit)
@@ -280,8 +287,8 @@ type AjaxRequest a =
280287
foreign import _ajax
281288
:: forall a
282289
. Fn4
283-
String
284-
String
285-
(String -> String -> ResponseHeader)
286-
(AjaxRequest a)
287-
(AC.EffectFnAff (Response Foreign))
290+
String
291+
String
292+
(String -> String -> ResponseHeader)
293+
(AjaxRequest a)
294+
(AC.EffectFnAff (Response Foreign))

test/Main.purs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log
5555
let ok200 = StatusCode 200
5656
let notFound404 = StatusCode 404
5757

58-
{ server, port } fromEffectFnAff startServer
58+
{ server, port } <- fromEffectFnAff startServer
5959
finally (fromEffectFnAff (stopServer server)) do
6060
A.log ("Test server running on port " <> show port)
6161

@@ -75,17 +75,17 @@ main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log
7575

7676
A.log "GET /not-json: invalid JSON with Foreign response should return an error"
7777
AX.get ResponseFormat.json doesNotExist >>= assertLeft >>= case _ of
78-
AX.ResponseBodyError _ _ pure unit
79-
other logAny' other *> assertFail "Expected a ResponseBodyError"
78+
AX.ResponseBodyError _ _ -> pure unit
79+
other -> logAny' other *> assertFail "Expected a ResponseBodyError"
8080

8181
A.log "GET /not-json: invalid JSON with String response should be ok"
8282
AX.get ResponseFormat.string notJson >>= assertRight >>= \res -> do
8383
assertEq ok200 res.status
8484

8585
A.log "GET /slow with timeout: should return an error"
8686
(AX.request $ AX.defaultRequest { url = slow, timeout = Just (Milliseconds 100.0) }) >>= assertLeft >>= case _ of
87-
AX.TimeoutError pure unit
88-
other logAny' other *> assertFail "Expected a TimeoutError"
87+
AX.TimeoutError -> pure unit
88+
other -> logAny' other *> assertFail "Expected a TimeoutError"
8989

9090
A.log "POST /mirror: should use the POST method"
9191
AX.post ResponseFormat.json mirror (Just (RequestBody.string "test")) >>= assertRight >>= \res -> do
@@ -102,7 +102,6 @@ main = void $ runAff (either (\e -> logShow e *> throwException e) (const $ log
102102
A.log "Testing CORS, HTTPS"
103103
AX.get ResponseFormat.json "https://cors-test.appspot.com/test" >>= assertRight >>= \res -> do
104104
assertEq ok200 res.status
105-
-- assertEq (Just "test=test") (lookupHeader "Set-Cookie" res.headers)
106105

107106
A.log "Testing cancellation"
108107
forkAff (AX.post_ mirror (Just (RequestBody.string "do it now"))) >>= killFiber (error "Pull the cord!")

0 commit comments

Comments
 (0)