Skip to content

Commit 0eca11d

Browse files
Introduce purs-tidy formatter (#49)
* Add purs-tidy formatter * Run purs-tidy * review
1 parent c2a32c2 commit 0eca11d

File tree

13 files changed

+169
-132
lines changed

13 files changed

+169
-132
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
@@ -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

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

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 (#49 by @thomashoneyman)
1415

1516
## [v8.1.0](https://github.com/purescript-contrib/purescript-pathy/releases/tag/v8.1.0) - 2021-05-06
1617

packages.dhall

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
let upstream =
2-
https://github.com/purescript/package-sets/releases/download/psc-0.14.3-20210722/packages.dhall sha256:1ceb43aa59436bf5601bac45f6f3781c4e1f0e4c2b8458105b018e5ed8c30f8c
2+
https://github.com/purescript/package-sets/releases/download/psc-0.14.4-20211109/packages.dhall sha256:e8d8d5b339f6d46d950da90037c6c38e8809f7e34f727373089ab82c080fc709
33

44
in upstream

src/Pathy/Gen.purs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,45 +25,45 @@ import Data.String.NonEmpty.CodeUnits (cons)
2525
import Pathy (AbsDir, AbsFile, AbsPath, Dir, File, RelDir, RelFile, RelPath, (</>))
2626
import Pathy as P
2727

28-
genName m a. MonadGen m MonadRec m m (P.Name a)
28+
genName :: forall m a. MonadGen m => MonadRec m => m (P.Name a)
2929
genName = map P.Name $ cons <$> genChar <*> SG.genString genChar
3030
where
31-
genChar = Gen.oneOf $ CG.genDigitChar :| [CG.genAlpha]
31+
genChar = Gen.oneOf $ CG.genDigitChar :| [ CG.genAlpha ]
3232

33-
genDirName :: m. MonadGen m MonadRec m m (P.Name Dir)
33+
genDirName :: forall m. MonadGen m => MonadRec m => m (P.Name Dir)
3434
genDirName = genName
3535

36-
genFileName :: m. MonadGen m MonadRec m m (P.Name File)
36+
genFileName :: forall m. MonadGen m => MonadRec m => m (P.Name File)
3737
genFileName = genName
3838

3939
genAbsDirPath :: forall m. MonadGen m => MonadRec m => m AbsDir
40-
genAbsDirPath = Gen.sized \size do
41-
newSize Gen.chooseInt 0 size
40+
genAbsDirPath = Gen.sized \size -> do
41+
newSize <- Gen.chooseInt 0 size
4242
Gen.resize (const newSize) do
43-
parts L.List (P.Name Dir) Gen.unfoldable genName
43+
parts :: L.List (P.Name Dir) <- Gen.unfoldable genName
4444
pure $ foldr (flip P.appendPath <<< P.dir') P.rootDir parts
4545

4646
genAbsFilePath :: forall m. MonadGen m => MonadRec m => m AbsFile
4747
genAbsFilePath = do
48-
dir genAbsDirPath
49-
file genName
48+
dir <- genAbsDirPath
49+
file <- genName
5050
pure $ dir </> P.file' file
5151

5252
genAbsAnyPath :: forall m. MonadGen m => MonadRec m => m AbsPath
53-
genAbsAnyPath = Gen.oneOf $ (Left <$> genAbsDirPath) :| [Right <$> genAbsFilePath]
53+
genAbsAnyPath = Gen.oneOf $ (Left <$> genAbsDirPath) :| [ Right <$> genAbsFilePath ]
5454

5555
genRelDirPath :: forall m. MonadGen m => MonadRec m => m RelDir
56-
genRelDirPath = Gen.sized \size do
57-
newSize Gen.chooseInt 0 size
56+
genRelDirPath = Gen.sized \size -> do
57+
newSize <- Gen.chooseInt 0 size
5858
Gen.resize (const newSize) do
59-
parts L.List (P.Name Dir) Gen.unfoldable genName
59+
parts :: L.List (P.Name Dir) <- Gen.unfoldable genName
6060
pure $ foldr (flip P.appendPath <<< P.dir') P.currentDir parts
6161

6262
genRelFilePath :: forall m. MonadGen m => MonadRec m => m RelFile
6363
genRelFilePath = do
64-
dir genRelDirPath
65-
file genName
64+
dir <- genRelDirPath
65+
file <- genName
6666
pure $ dir </> P.file' file
6767

6868
genRelAnyPath :: forall m. MonadGen m => MonadRec m => m RelPath
69-
genRelAnyPath = Gen.oneOf $ (Left <$> genRelDirPath) :| [Right <$> genRelFilePath]
69+
genRelAnyPath = Gen.oneOf $ (Left <$> genRelDirPath) :| [ Right <$> genRelFilePath ]

src/Pathy/Name.purs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ alterExtension
8888
. (Maybe NonEmptyString -> Maybe NonEmptyString)
8989
-> Name n
9090
-> Name n
91-
alterExtension f n =
91+
alterExtension f n = do
9292
let spn = splitName n
93-
in joinName spn{ext = f spn.ext}
93+
joinName spn { ext = f spn.ext }
9494

9595
-- | A class for creating `Name` values from type-level strings. This allows us
9696
-- | to guarantee that a name is not empty at compile-time.

src/Pathy/Parser.purs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,14 @@ import Pathy.Phantom (class IsRelOrAbs, Dir)
2727

2828
newtype Parser = Parser
2929
( forall z
30-
. (RelDir -> z)
31-
-> (AbsDir -> z)
32-
-> (RelFile -> z)
33-
-> (AbsFile -> z)
34-
-> z
35-
-> String
36-
-> z)
30+
. (RelDir -> z)
31+
-> (AbsDir -> z)
32+
-> (RelFile -> z)
33+
-> (AbsFile -> z)
34+
-> z
35+
-> String
36+
-> z
37+
)
3738

3839
-- | A parser for POSIX paths.
3940
posixParser :: Parser
@@ -75,13 +76,13 @@ buildPath z init k segs =
7576
| NES.toString name == "." -> k $ Left (go segs')
7677
| otherwise -> k $ Right (extendPath (go segs') (Name name))
7778
where
78-
go :: List NonEmptyString -> Path a Dir
79-
go = case _ of
80-
Nil -> init
81-
name : segs'
82-
| NES.toString name == ".." -> parentOf (go segs')
83-
| NES.toString name == "." -> go segs'
84-
| otherwise -> extendPath (go segs') (Name name)
79+
go :: List NonEmptyString -> Path a Dir
80+
go = case _ of
81+
Nil -> init
82+
name : segs'
83+
| NES.toString name == ".." -> parentOf (go segs')
84+
| NES.toString name == "." -> go segs'
85+
| otherwise -> extendPath (go segs') (Name name)
8586

8687
parsePath
8788
:: forall z

src/Pathy/Path.purs

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,19 @@ module Pathy.Path
1818
, in'
1919
, parentOf
2020
, extendPath
21-
, appendPath, (</>)
22-
, parentAppend, (<..>)
21+
, appendPath
22+
, (</>)
23+
, parentAppend
24+
, (<..>)
2325
, foldPath
2426
, peel
2527
, peelFile
2628
, name
2729
, fileName
2830
, rename
2931
, renameTraverse
30-
, setExtension, (<.>)
32+
, setExtension
33+
, (<.>)
3134
, relativeTo
3235
, refine
3336
) where
@@ -272,24 +275,26 @@ infixl 6 setExtension as <.>
272275
relativeTo :: forall b. Path Abs b -> Path Abs Dir -> Path Rel b
273276
relativeTo p = coeB <<< step Init (coeD p)
274277
where
275-
step :: Path Rel Dir -> Path Abs Dir -> Path Abs Dir -> Path Rel Dir
276-
step acc = case _, _ of
277-
p', rp' | p' == rp' -> acc
278-
Init, In rp' _ -> step (ParentOf acc) Init rp'
279-
In p' n, Init -> In (step acc p' Init) n
280-
In p' n, rp'
281-
| p' == rp' -> In acc n
282-
| otherwise -> In (step acc p' rp') n
283-
_, _ ->
284-
unsafeCrashWith "`ParentOf` in Pathy.relativeTo (this should be impossible)"
285-
-- Unfortunately we can't avoid some coercions in this function unless
286-
-- we actually write two different verions of `relativeTo` for file/dir
287-
-- paths. Since the actual data representation is same either way the
288-
-- coercions are safe.
289-
coeD :: forall a. Path a b -> Path a Dir
290-
coeD = unsafeCoerce
291-
coeB :: forall a. Path a Dir -> Path a b
292-
coeB = unsafeCoerce
278+
step :: Path Rel Dir -> Path Abs Dir -> Path Abs Dir -> Path Rel Dir
279+
step acc = case _, _ of
280+
p', rp' | p' == rp' -> acc
281+
Init, In rp' _ -> step (ParentOf acc) Init rp'
282+
In p' n, Init -> In (step acc p' Init) n
283+
In p' n, rp'
284+
| p' == rp' -> In acc n
285+
| otherwise -> In (step acc p' rp') n
286+
_, _ ->
287+
unsafeCrashWith "`ParentOf` in Pathy.relativeTo (this should be impossible)"
288+
289+
-- Unfortunately we can't avoid some coercions in this function unless
290+
-- we actually write two different verions of `relativeTo` for file/dir
291+
-- paths. Since the actual data representation is same either way the
292+
-- coercions are safe.
293+
coeD :: forall a. Path a b -> Path a Dir
294+
coeD = unsafeCoerce
295+
296+
coeB :: forall a. Path a Dir -> Path a b
297+
coeB = unsafeCoerce
293298

294299
-- | Refines path segments but does not change anything else.
295300
refine
@@ -301,7 +306,7 @@ refine
301306
-> Path a b
302307
refine f d = go
303308
where
304-
go :: forall a' b'. IsDirOrFile b' => Path a' b' -> Path a' b'
305-
go Init = Init
306-
go (ParentOf p) = ParentOf (go p)
307-
go (In p n) = In (go p) (onDirOrFile (_ <<< d) (_ <<< f) n)
309+
go :: forall a' b'. IsDirOrFile b' => Path a' b' -> Path a' b'
310+
go Init = Init
311+
go (ParentOf p) = ParentOf (go p)
312+
go (In p n) = In (go p) (onDirOrFile (_ <<< d) (_ <<< f) n)

src/Pathy/Phantom.purs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,21 @@ class IsRelOrAbs :: RelOrAbs -> Constraint
2020
class IsRelOrAbs a where
2121
onRelOrAbs
2222
:: forall (f :: RelOrAbs -> DirOrFile -> Type) b r
23-
. ((f Rel b -> f a b) -> f Rel b -> r)
23+
. ((f Rel b -> f a b) -> f Rel b -> r)
2424
-> ((f Abs b -> f a b) -> f Abs b -> r)
2525
-> f a b
2626
-> r
2727

28-
instance relIsRelOrAbs :: IsRelOrAbs Rel where onRelOrAbs f _ = f identity
29-
instance absIsRelOrAbs :: IsRelOrAbs Abs where onRelOrAbs _ f = f identity
28+
instance relIsRelOrAbs :: IsRelOrAbs Rel where
29+
onRelOrAbs f _ = f identity
30+
31+
instance absIsRelOrAbs :: IsRelOrAbs Abs where
32+
onRelOrAbs _ f = f identity
3033

3134
-- | Folds over a value that uses `RelOrAbs` to produce a new result.
3235
foldRelOrAbs
3336
:: forall f a b r
34-
. IsRelOrAbs a
37+
. IsRelOrAbs a
3538
=> (f Rel b -> r)
3639
-> (f Abs b -> r)
3740
-> f a b
@@ -61,13 +64,16 @@ class IsDirOrFile b where
6164
-> f b
6265
-> r
6366

64-
instance isDirOrFileDir :: IsDirOrFile Dir where onDirOrFile f _ = f identity
65-
instance isDirOrFileFile :: IsDirOrFile File where onDirOrFile _ f = f identity
67+
instance isDirOrFileDir :: IsDirOrFile Dir where
68+
onDirOrFile f _ = f identity
69+
70+
instance isDirOrFileFile :: IsDirOrFile File where
71+
onDirOrFile _ f = f identity
6672

6773
-- | Folds over a value that uses `DirOrFile` to produce a new result.
6874
foldDirOrFile
6975
:: forall f b r
70-
. IsDirOrFile b
76+
. IsDirOrFile b
7177
=> (f Dir -> r)
7278
-> (f File -> r)
7379
-> f b

0 commit comments

Comments
 (0)