diff options
author | stuebinm | 2021-11-09 20:24:17 +0100 |
---|---|---|
committer | stuebinm | 2021-11-09 20:42:10 +0100 |
commit | 652c2030c5ef39bf1dd34d26064e1059431898f0 (patch) | |
tree | 7100fbdfabbfa0f237e05ae1d0d2e2debb380125 /lib/LintWriter.hs | |
parent | d0dc669c495f5f9e3dae20481e0aae183f606519 (diff) |
first example of a map adjustment
this also includes some more monad plumbing, and an option for the
linter to actually write things out again. Some of the previous commit
was reverted a bit since it turned out to be stupid, but overall it was
suprisingly easy once I got around to it, so yay! i guess
Also includes a fairly silly example of how to use it.
Diffstat (limited to '')
-rw-r--r-- | lib/LintWriter.hs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/lib/LintWriter.hs b/lib/LintWriter.hs index 8d91948..54a5954 100644 --- a/lib/LintWriter.hs +++ b/lib/LintWriter.hs @@ -84,9 +84,12 @@ resultToOffers (LintResult a) = mapMaybe lintToOffer $ snd a resultToLints :: LintResult a -> [Lint] resultToLints (LintResult res) = snd res --- | run a linter +resultToAdjusted :: LintResult a -> a +resultToAdjusted (LintResult res) = fst res + +-- | run a linter. Returns the adjusted context, and a list of lints runLintWriter :: ctxt -> Context -> LintWriter ctxt -> LintResult ctxt -runLintWriter c c' linter = LintResult (c, fst $ fromLinterState lints) +runLintWriter c c' linter = LintResult (snd $ fromLinterState lints,fst $ fromLinterState lints) where lints = snd $ runReader ranstate (c',c) ranstate = runStateT linter (LinterState ([], c)) @@ -104,6 +107,8 @@ dependsOn dep = tell' $ Depends dep offersEntrypoint :: Text -> LintWriter a offersEntrypoint text = tell' $ Offers text +-- | adjusts the context. Gets a copy of the /current/ context, i.e. one which might +-- have already been changed by other lints adjust :: (a -> a) -> LintWriter a adjust f = modify $ LinterState . second f . fromLinterState @@ -114,6 +119,8 @@ warn = lint Warning forbid = lint Forbidden complain = lint Error + +-- | get the context as it was originally, without any modifications askContext :: LintWriter' a a askContext = lift $ asks snd |