Skip to content

Commit a1d9a48

Browse files
Introduce purs-tidy formatter (#27)
* Add purs-tidy formatter * Run purs-tidy
1 parent 9d8817f commit a1d9a48

File tree

7 files changed

+177
-160
lines changed

7 files changed

+177
-160
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 (#27 by @thomashoneyman)
1415

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

src/Effect/AVar.purs

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ import Data.Maybe (Maybe(..))
2424
import Effect (Effect)
2525
import Effect.Exception (Error)
2626

27-
type AVarCallback a = (Either Error a Effect Unit)
27+
type AVarCallback a = (Either Error a -> Effect Unit)
2828

29-
foreign import data AVar Type Type
29+
foreign import data AVar :: Type -> Type
3030

3131
type role AVar representational
3232

@@ -36,92 +36,92 @@ data AVarStatus a
3636
| Empty
3737

3838
-- | Creates a new empty AVar.
39-
foreign import empty a. Effect (AVar a)
39+
foreign import empty :: forall a. Effect (AVar a)
4040

4141
-- | Creates a fresh AVar with an initial value.
42-
new a. a Effect (AVar a)
42+
new :: forall a. a -> Effect (AVar a)
4343
new = _newVar
4444

4545
-- | Kills the AVar with an exception. All pending and future actions will
4646
-- | resolve immediately with the provided exception.
47-
kill a. Error AVar a Effect Unit
47+
kill :: forall a. Error -> AVar a -> Effect Unit
4848
kill err avar = Fn.runFn3 _killVar ffiUtil err avar
4949

5050
-- | Sets the value of the AVar. If the AVar is already filled, it will be
5151
-- | queued until the value is emptied. Multiple puts will resolve in order as
5252
-- | the AVar becomes available. Returns an effect which will remove the
5353
-- | callback from the pending queue.
54-
put a. a AVar a AVarCallback Unit Effect (Effect Unit)
54+
put :: forall a. a -> AVar a -> AVarCallback Unit -> Effect (Effect Unit)
5555
put value avar cb = Fn.runFn4 _putVar ffiUtil value avar cb
5656

5757
-- | Attempts to synchronously fill an AVar. If the AVar is already filled,
5858
-- | this will do nothing. Returns true or false depending on if it succeeded.
59-
tryPut a. a AVar a Effect Boolean
59+
tryPut :: forall a. a -> AVar a -> Effect Boolean
6060
tryPut value avar = Fn.runFn3 _tryPutVar ffiUtil value avar
6161

6262
-- | Takes the AVar value, leaving it empty. If the AVar is already empty,
6363
-- | the callback will be queued until the AVar is filled. Multiple takes will
6464
-- | resolve in order as the AVar fills. Returns an effect which will remove
6565
-- | the callback from the pending queue.
66-
take a. AVar a AVarCallback a Effect (Effect Unit)
66+
take :: forall a. AVar a -> AVarCallback a -> Effect (Effect Unit)
6767
take avar cb = Fn.runFn3 _takeVar ffiUtil avar cb
6868

6969
-- | Attempts to synchronously take an AVar value, leaving it empty. If the
7070
-- | AVar is empty, this will return `Nothing`.
71-
tryTake a. AVar a Effect (Maybe a)
71+
tryTake :: forall a. AVar a -> Effect (Maybe a)
7272
tryTake avar = Fn.runFn2 _tryTakeVar ffiUtil avar
7373

7474
-- | Reads the AVar value. Unlike `take`, this will not leave the AVar empty.
7575
-- | If the AVar is empty, this will queue until it is filled. Multiple reads
7676
-- | will resolve at the same time, as soon as possible.
77-
read a. AVar a AVarCallback a Effect (Effect Unit)
77+
read :: forall a. AVar a -> AVarCallback a -> Effect (Effect Unit)
7878
read avar cb = Fn.runFn3 _readVar ffiUtil avar cb
7979

8080
-- | Attempts to synchronously read an AVar. If the AVar is empty, this will
8181
-- | return `Nothing`.
82-
tryRead a. AVar a Effect (Maybe a)
82+
tryRead :: forall a. AVar a -> Effect (Maybe a)
8383
tryRead avar = Fn.runFn2 _tryReadVar ffiUtil avar
8484

8585
-- | Synchronously checks the status of an AVar.
86-
status a. AVar a Effect (AVarStatus a)
86+
status :: forall a. AVar a -> Effect (AVarStatus a)
8787
status avar = Fn.runFn2 _status ffiUtil avar
8888

89-
isEmpty a. AVarStatus a Boolean
89+
isEmpty :: forall a. AVarStatus a -> Boolean
9090
isEmpty = case _ of
91-
Empty true
92-
_ false
91+
Empty -> true
92+
_ -> false
9393

94-
isFilled a. AVarStatus a Boolean
94+
isFilled :: forall a. AVarStatus a -> Boolean
9595
isFilled = case _ of
96-
Filled _ true
97-
_ false
96+
Filled _ -> true
97+
_ -> false
9898

99-
isKilled a. AVarStatus a Boolean
99+
isKilled :: forall a. AVarStatus a -> Boolean
100100
isKilled = case _ of
101-
Killed _ true
102-
_ false
103-
104-
foreign import _newVar a. a Effect (AVar a)
105-
foreign import _killVar a. Fn.Fn3 FFIUtil Error (AVar a) (Effect Unit)
106-
foreign import _putVar a. Fn.Fn4 FFIUtil a (AVar a) (AVarCallback Unit) (Effect (Effect Unit))
107-
foreign import _tryPutVar a. Fn.Fn3 FFIUtil a (AVar a) (Effect Boolean)
108-
foreign import _takeVar a. Fn.Fn3 FFIUtil (AVar a) (AVarCallback a) (Effect (Effect Unit))
109-
foreign import _tryTakeVar a. Fn.Fn2 FFIUtil (AVar a) (Effect (Maybe a))
110-
foreign import _readVar a. Fn.Fn3 FFIUtil (AVar a) (AVarCallback a) (Effect (Effect Unit))
111-
foreign import _tryReadVar a. Fn.Fn2 FFIUtil (AVar a) (Effect (Maybe a))
112-
foreign import _status a. Fn.Fn2 FFIUtil (AVar a) (Effect (AVarStatus a))
101+
Killed _ -> true
102+
_ -> false
103+
104+
foreign import _newVar :: forall a. a -> Effect (AVar a)
105+
foreign import _killVar :: forall a. Fn.Fn3 FFIUtil Error (AVar a) (Effect Unit)
106+
foreign import _putVar :: forall a. Fn.Fn4 FFIUtil a (AVar a) (AVarCallback Unit) (Effect (Effect Unit))
107+
foreign import _tryPutVar :: forall a. Fn.Fn3 FFIUtil a (AVar a) (Effect Boolean)
108+
foreign import _takeVar :: forall a. Fn.Fn3 FFIUtil (AVar a) (AVarCallback a) (Effect (Effect Unit))
109+
foreign import _tryTakeVar :: forall a. Fn.Fn2 FFIUtil (AVar a) (Effect (Maybe a))
110+
foreign import _readVar :: forall a. Fn.Fn3 FFIUtil (AVar a) (AVarCallback a) (Effect (Effect Unit))
111+
foreign import _tryReadVar :: forall a. Fn.Fn2 FFIUtil (AVar a) (Effect (Maybe a))
112+
foreign import _status :: forall a. Fn.Fn2 FFIUtil (AVar a) (Effect (AVarStatus a))
113113

114114
type FFIUtil =
115-
{ left a b. a Either a b
116-
, right a b. b Either a b
117-
, nothing a. Maybe a
118-
, just a. a Maybe a
119-
, killed a. Error AVarStatus a
120-
, filled a. a AVarStatus a
121-
, empty a. AVarStatus a
115+
{ left :: forall a b. a -> Either a b
116+
, right :: forall a b. b -> Either a b
117+
, nothing :: forall a. Maybe a
118+
, just :: forall a. a -> Maybe a
119+
, killed :: forall a. Error -> AVarStatus a
120+
, filled :: forall a. a -> AVarStatus a
121+
, empty :: forall a. AVarStatus a
122122
}
123123

124-
ffiUtil FFIUtil
124+
ffiUtil :: FFIUtil
125125
ffiUtil =
126126
{ left: Left
127127
, right: Right

src/Effect/Aff/AVar.purs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,57 @@ import Effect.Class (liftEffect)
2121
import Effect.Exception (Error)
2222

2323
-- | Creates a fresh AVar with an initial value.
24-
new a. a Aff (AVar a)
24+
new :: forall a. a -> Aff (AVar a)
2525
new = liftEffect <<< AVar.new
2626

2727
-- | Creates a fresh AVar.
28-
empty a. Aff (AVar a)
28+
empty :: forall a. Aff (AVar a)
2929
empty = liftEffect AVar.empty
3030

3131
-- | Synchronously checks the status of an AVar.
32-
status a. AVar a Aff (AVar.AVarStatus a)
32+
status :: forall a. AVar a -> Aff (AVar.AVarStatus a)
3333
status = liftEffect <<< AVar.status
3434

3535
-- | Takes the AVar value, leaving it empty. If the AVar is already empty,
3636
-- | the callback will be queued until the AVar is filled. Multiple takes will
3737
-- | resolve in order as the AVar fills.
38-
take a. AVar a Aff a
39-
take avar = makeAff \k do
40-
c AVar.take avar k
38+
take :: forall a. AVar a -> Aff a
39+
take avar = makeAff \k -> do
40+
c <- AVar.take avar k
4141
pure (effectCanceler c)
4242

4343
-- | Attempts to synchronously take an AVar value, leaving it empty. If the
4444
-- | AVar is empty, this will return `Nothing`.
45-
tryTake a. AVar a Aff (Maybe a)
45+
tryTake :: forall a. AVar a -> Aff (Maybe a)
4646
tryTake = liftEffect <<< AVar.tryTake
4747

4848
-- | Sets the value of the AVar. If the AVar is already filled, it will be
4949
-- | queued until the value is emptied. Multiple puts will resolve in order as
5050
-- | the AVar becomes available.
51-
put a. a AVar a Aff Unit
52-
put value avar = makeAff \k do
53-
c AVar.put value avar k
51+
put :: forall a. a -> AVar a -> Aff Unit
52+
put value avar = makeAff \k -> do
53+
c <- AVar.put value avar k
5454
pure (effectCanceler c)
5555

5656
-- | Attempts to synchronously fill an AVar. If the AVar is already filled,
5757
-- | this will do nothing. Returns true or false depending on if it succeeded.
58-
tryPut a. a AVar a Aff Boolean
58+
tryPut :: forall a. a -> AVar a -> Aff Boolean
5959
tryPut value = liftEffect <<< AVar.tryPut value
6060

6161
-- | Reads the AVar value. Unlike `take`, this will not leave the AVar empty.
6262
-- | If the AVar is empty, this will queue until it is filled. Multiple reads
6363
-- | will resolve at the same time, as soon as possible.
64-
read a. AVar a Aff a
65-
read avar = makeAff \k do
66-
c AVar.read avar k
64+
read :: forall a. AVar a -> Aff a
65+
read avar = makeAff \k -> do
66+
c <- AVar.read avar k
6767
pure (effectCanceler c)
6868

6969
-- | Attempts to synchronously read an AVar. If the AVar is empty, this will
7070
-- | return `Nothing`.
71-
tryRead a. AVar a Aff (Maybe a)
71+
tryRead :: forall a. AVar a -> Aff (Maybe a)
7272
tryRead = liftEffect <<< AVar.tryRead
7373

7474
-- | Kills the AVar with an exception. All pending and future actions will
7575
-- | resolve immediately with the provided exception.
76-
kill a. Error AVar a Aff Unit
76+
kill :: forall a. Error -> AVar a -> Aff Unit
7777
kill error = liftEffect <<< AVar.kill error

0 commit comments

Comments
 (0)