diff options
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 |