Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
walint
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
hub
walint
Commits
04b98e4d
Unverified
Commit
04b98e4d
authored
Sep 23, 2021
by
stuebinm
Browse files
Options
Downloads
Patches
Plain Diff
some documentation
parent
7e77e633
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/CheckDir.hs
+11
-2
11 additions, 2 deletions
lib/CheckDir.hs
lib/Paths.hs
+9
-3
9 additions, 3 deletions
lib/Paths.hs
with
20 additions
and
5 deletions
lib/CheckDir.hs
+
11
−
2
View file @
04b98e4d
...
@@ -32,11 +32,13 @@ setFromList = M.fromList . flip zip (repeat ())
...
@@ -32,11 +32,13 @@ setFromList = M.fromList . flip zip (repeat ())
listFromSet
::
Set
a
->
[
a
]
listFromSet
::
Set
a
->
[
a
]
listFromSet
=
map
fst
.
M
.
toList
listFromSet
=
map
fst
.
M
.
toList
-- | Result of linting an entire directory / repository
data
DirResult
=
DirResult
data
DirResult
=
DirResult
{
dirresultMaps
::
Map
FilePath
MapResult
{
dirresultMaps
::
Map
FilePath
MapResult
,
dirresultDeps
::
[
Text
]
,
dirresultDeps
::
[
Text
]
}
deriving
(
Generic
,
ToJSON
)
}
deriving
(
Generic
,
ToJSON
)
instance
PrettyPrint
DirResult
where
instance
PrettyPrint
DirResult
where
prettyprint
res
=
T
.
concat
prettyprint
res
=
T
.
concat
(
map
(
\
(
p
,
lints
)
->
"
\n
in "
<>
T
.
pack
p
<>
":
\n
"
<>
prettyprint
lints
)
$
M
.
toList
$
dirresultMaps
res
)
(
map
(
\
(
p
,
lints
)
->
"
\n
in "
<>
T
.
pack
p
<>
":
\n
"
<>
prettyprint
lints
)
$
M
.
toList
$
dirresultMaps
res
)
...
@@ -54,11 +56,18 @@ instance Monoid DirResult where
...
@@ -54,11 +56,18 @@ instance Monoid DirResult where
}
}
-- TODO: options?
-- | The nice function to check an entire repository with.
-- gets a prefix (i.e. the bare path to the repository) and
-- a root (i.e. the name of the file containing the entrypoint
-- map within that file)
recursiveCheckDir
::
FilePath
->
FilePath
->
IO
DirResult
recursiveCheckDir
::
FilePath
->
FilePath
->
IO
DirResult
recursiveCheckDir
prefix
root
=
recursiveCheckDir'
prefix
[
root
]
mempty
mempty
recursiveCheckDir
prefix
root
=
recursiveCheckDir'
prefix
[
root
]
mempty
mempty
-- | The less-nice function for checking an entire repository.
--
-- Strictly speaking it probably doesn't need to have `done` and
-- `acc` since they are essentially the same thing, but doing it
-- like this seemed convenient at the time
recursiveCheckDir'
::
FilePath
->
[
FilePath
]
->
Set
FilePath
->
DirResult
->
IO
DirResult
recursiveCheckDir'
::
FilePath
->
[
FilePath
]
->
Set
FilePath
->
DirResult
->
IO
DirResult
recursiveCheckDir'
prefix
paths
done
acc
=
do
recursiveCheckDir'
prefix
paths
done
acc
=
do
putStrLn
$
"linting "
<>
show
paths
putStrLn
$
"linting "
<>
show
paths
...
...
This diff is collapsed.
Click to expand it.
lib/Paths.hs
+
9
−
3
View file @
04b98e4d
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE OverloadedStrings #-}
-- |
-- |
Paths are horrible, so they have their own module now.
-- I just hope you are running this on some kind of Unix
module
Paths
where
module
Paths
where
import
Data.Text
(
Text
)
import
Data.Text
(
Text
)
...
@@ -12,7 +12,8 @@ import Text.Regex.TDFA
...
@@ -12,7 +12,8 @@ import Text.Regex.TDFA
import
Util
(
PrettyPrint
(
prettyprint
))
import
Util
(
PrettyPrint
(
prettyprint
))
-- | a normalised path: a number of "upwards" steps, and
-- | a normalised path: a number of "upwards" steps, and
-- a path without any . or .. in it. Also possibly a
-- fragment, mostly for map links.
data
RelPath
=
Path
Int
Text
(
Maybe
Text
)
data
RelPath
=
Path
Int
Text
(
Maybe
Text
)
deriving
(
Show
,
Eq
,
Ord
)
deriving
(
Show
,
Eq
,
Ord
)
...
@@ -37,6 +38,11 @@ instance PrettyPrint RelPath where
...
@@ -37,6 +38,11 @@ instance PrettyPrint RelPath where
prettyprint
(
Path
up
rest
_
)
=
ups
<>
rest
prettyprint
(
Path
up
rest
_
)
=
ups
<>
rest
where
ups
=
T
.
concat
$
replicate
up
"../"
where
ups
=
T
.
concat
$
replicate
up
"../"
-- | Normalises a path.
--
-- It takes a `prefix`, and will "truncate" the .. operator
-- at the end of the prefix, i.e. it will never return paths
-- that lie (naïvely) outside of the prefix.
normalise
::
FilePath
->
RelPath
->
FilePath
normalise
::
FilePath
->
RelPath
->
FilePath
normalise
prefix
(
Path
0
path
_
)
=
prefix
</>
T
.
unpack
path
normalise
prefix
(
Path
0
path
_
)
=
prefix
</>
T
.
unpack
path
normalise
prefix
(
Path
i
path
_
)
=
normalise
prefix
(
Path
i
path
_
)
=
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment