Skip to content

Commit fb5e605

Browse files
Merge pull request #6 from purescript-contrib/trh/purs-tidy
Introduce purs-tidy formatter
2 parents a9b4ab0 + 75cd7e7 commit fb5e605

File tree

6 files changed

+45
-25
lines changed

6 files changed

+45
-25
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 0 deletions
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
@@ -38,3 +40,6 @@ jobs:
3840

3941
- name: Run tests
4042
run: spago -x test.dhall test --no-install
43+
44+
- name: Check formatting
45+
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

67
output
78
generated-docs

.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+
}

src/Data/Float32.purs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
11
module Data.Float32
2-
( Float32, fromNumber, fromNumber', toNumber
2+
( Float32
3+
, fromNumber
4+
, fromNumber'
5+
, toNumber
36
) where
47

58
import Prelude
6-
( class Eq, class Ord, class Show, class Semiring, class Ring, class Bounded, class EuclideanRing
7-
, class CommutativeRing, class DivisionRing
8-
, top, bottom, (==), (||))
9-
import Data.Maybe (Maybe (..))
9+
( class Eq
10+
, class Ord
11+
, class Show
12+
, class Semiring
13+
, class Ring
14+
, class Bounded
15+
, class EuclideanRing
16+
, class CommutativeRing
17+
, class DivisionRing
18+
, top
19+
, bottom
20+
, (==)
21+
, (||)
22+
)
23+
import Data.Maybe (Maybe(..))
1024

1125
-- | [32-bit single-precision floating-point](https://en.wikipedia.org/wiki/Single-precision_floating-point_format)
1226
-- | number.
@@ -24,17 +38,17 @@ instance boundedFloat32 :: Bounded Float32 where
2438
top = float32Top
2539
bottom = float32Bottom
2640

27-
2841
foreign import float32Top :: Float32
2942
foreign import float32Bottom :: Float32
3043

31-
3244
-- | Uses `Math.fround()` to convert to a `Float32`.
3345
-- | Returns `Nothing` when outside the range.
3446
fromNumber :: Number -> Maybe Float32
3547
fromNumber x =
36-
let r = fromNumberImpl x
37-
in if r == top || r == bottom then Nothing else Just (Float32 r)
48+
let
49+
r = fromNumberImpl x
50+
in
51+
if r == top || r == bottom then Nothing else Just (Float32 r)
3852

3953
-- | Uses `Math.fround()` to convert to a `Float32`.
4054
-- | Returns *0.0* when outside the range.
@@ -43,7 +57,6 @@ fromNumber' x = case fromNumber x of
4357
Nothing -> Float32 0.0
4458
Just y -> y
4559

46-
4760
foreign import fromNumberImpl :: Number -> Number
4861

4962
toNumber :: Float32 -> Number

src/Data/Float32/Gen.purs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,5 @@ import Prelude ((<$>))
44
import Data.Float32 (Float32, fromNumber', toNumber)
55
import Control.Monad.Gen.Class (class MonadGen, chooseFloat)
66

7-
87
chooseFloat32 :: forall m. MonadGen m => Float32 -> Float32 -> m Float32
98
chooseFloat32 a b = fromNumber' <$> chooseFloat (toNumber a) (toNumber b)

test/Main.purs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Test.QuickCheck.Laws.Data (checkBounded, checkCommutativeRing, checkEq, c
1010
import Type.Proxy (Proxy(..))
1111

1212
newtype Float32' = Float32' Float32
13+
1314
derive newtype instance eqFloat32' :: Eq Float32'
1415
derive newtype instance ordFloat32' :: Ord Float32'
1516
derive newtype instance boundedFloat32' :: Bounded Float32'
@@ -21,26 +22,17 @@ derive newtype instance euclideanRingFloat32' :: EuclideanRing Float32'
2122
instance arbitraryFloat32' :: Arbitrary Float32' where
2223
arbitrary = Float32' <$> chooseFloat32 bottom top
2324

24-
2525
main :: Effect Unit
2626
main = do
27-
let p :: Proxy Float32'
28-
p = Proxy
27+
let
28+
p :: Proxy Float32'
29+
p = Proxy
2930
checkBounded p
3031
checkEq p
3132
checkOrd p
3233
checkSemiring p
3334
checkRing p
3435
checkCommutativeRing p
35-
-- checkDivisionRing p -- isn't a division ring because 32bit float isn't perfectly precise
36-
-- checkEuclideanRing p -- likewise for euclidean ring
37-
38-
39-
40-
41-
42-
43-
44-
45-
36+
-- checkDivisionRing p -- isn't a division ring because 32bit float isn't perfectly precise
37+
-- checkEuclideanRing p -- likewise for euclidean ring
4638

0 commit comments

Comments
 (0)