diff options
author | Ben Sima <ben@bsima.me> | 2021-01-26 19:05:58 -0500 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2021-01-26 19:50:06 -0500 |
commit | 82dbbc0eed18c86aae1a8f1f92a0c98684e63409 (patch) | |
tree | 66319a88e1f1f4383a15ac070079c3459b0fc7f8 /Biz/Lint.hs | |
parent | 0ec6b06acee62b57a50ed9718b8da31fced18c4d (diff) |
Create Biz.Log library, extracted from Biz.Bild
Diffstat (limited to 'Biz/Lint.hs')
-rw-r--r-- | Biz/Lint.hs | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/Biz/Lint.hs b/Biz/Lint.hs index ccbb393..26d4e6d 100644 --- a/Biz/Lint.hs +++ b/Biz/Lint.hs @@ -11,6 +11,7 @@ module Biz.Lint (main) where import Alpha import qualified Biz.Cli as Cli +import qualified Biz.Log as Log import Biz.Namespace (Ext (..), Namespace (..)) import qualified Biz.Namespace as Namespace import Biz.Test ((@=?)) @@ -18,7 +19,6 @@ import qualified Biz.Test as Test import qualified Control.Concurrent.Async as Async import qualified Data.String as String import qualified Data.Text as Text -import Rainbow (chunk, fore, green, putChunkLn, red, yellow) import qualified System.Directory as Directory import qualified System.Environment as Environment import qualified System.Exit as Exit @@ -34,7 +34,13 @@ move args = case Cli.getAllArgs args (Cli.argument "file") of files -> run (filter notcab files) >>= mapM printResult >>= exit test :: Test.Tree -test = Test.group "Biz.Lint" [Test.unit "id" <| 1 @=? 1] +test = + Test.group + "Biz.Lint" + [ Test.unit "haskell files return two Results" <| do + results <- run ["Biz/Lint.hs"] + length results @=? 2 + ] notcab :: FilePath -> Bool notcab ('_' : _) = False @@ -59,27 +65,19 @@ exit results = Exit.exitWith <| if n > 0 then Exit.ExitFailure n else Exit.ExitS bad Ok {status = Bad _} = True bad _ = False -schunk = chunk <. Text.pack - printResult :: Result -> IO Result -printResult r@(Warn err) = - (putChunkLn <| fore yellow <| "lint: warn: " <> chunk err) >> pure r +printResult r@(Warn err) = Log.warn ["lint", err] >> Log.br >> pure r printResult r@(Ok path_ linter_ (Bad err)) = - ( putChunkLn <| fore red <| "lint: baad: " - <> schunk linter_ - <> ": " - <> schunk path_ - ) + Log.fail ["lint", linter_, Text.pack path_] + >> Log.br >> if err == "" then pure r else putText (Text.pack err) >> pure r printResult r@(Ok path_ linter_ Good) = - ( putChunkLn <| fore green <| "lint: good: " - <> schunk linter_ - <> ": " - <> schunk path_ - ) + Log.good ["lint", linter_, Text.pack path_] + >> Log.br >> pure r printResult r@(NoOp path_) = - (putText <| "lint: noop: " <> Text.pack path_) + Log.info ["lint", "noop", Text.pack path_] + >> Log.br >> pure r changedFiles :: IO [FilePath] @@ -91,7 +89,7 @@ changedFiles = mergeBase >>= changed String.lines </ git ["diff", "--name-only", "--diff-filter=d", mb] -type Linter = String +type Linter = Text data Status = Good | Bad String deriving (Show) @@ -126,7 +124,7 @@ runOne root cwd path_ = lint :: Linter -> [String] -> FilePath -> IO Result lint bin args path_ = - Process.readProcessWithExitCode bin (args ++ [path_]) "" >>= \case + Process.readProcessWithExitCode (Text.unpack bin) (args ++ [path_]) "" >>= \case (Exit.ExitSuccess, _, _) -> pure <| Ok path_ bin Good (Exit.ExitFailure _, msg, _) -> pure <| Ok path_ bin <| Bad msg |