summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorstuebinm2022-02-18 18:09:23 +0100
committerstuebinm2022-02-18 18:09:23 +0100
commit7c49e6c367c9d021f3630c08a4a13ba9abc5df08 (patch)
treec278d23a6e39c353f5aa02d1ce9785122e1eea62 /src
parentfaa244e1a7e760be88054a5f15b3e115ad8e32e5 (diff)
switch to universum prelude
also don't keep adjusted maps around if not necessary
Diffstat (limited to '')
-rw-r--r--src/Main.hs30
-rw-r--r--src/Version.hs4
2 files changed, 15 insertions, 19 deletions
diff --git a/src/Main.hs b/src/Main.hs
index beee091..d2546f5 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -6,18 +6,15 @@
module Main where
-import Control.Monad (unless, when)
-import Control.Monad.Identity (Identity)
+import Universum
+
import Data.Aeson (eitherDecode, encode)
import Data.Aeson.Encode.Pretty (encodePretty)
import Data.Aeson.KeyMap (coercionToHashMap)
import qualified Data.ByteString.Lazy as LB
-import Data.Maybe (fromMaybe)
import qualified Data.Text.Encoding as T
import qualified Data.Text.IO as T
-import System.Exit (ExitCode (..), exitWith)
-import System.IO (hPutStrLn, stderr)
-import WithCli (Generic, HasArguments, withCli)
+import WithCli (HasArguments, withCli)
import CheckDir (recursiveCheckDir, resultIsFatal)
import LintConfig (LintConfig (..), patchConfig)
@@ -25,6 +22,7 @@ import Types (Level (..))
import Util (printPretty)
import WriteRepo (writeAdjustedRepository)
+import System.Exit (ExitCode (ExitFailure, ExitSuccess))
import qualified Version as V (version)
-- | the options this cli tool can take
@@ -58,7 +56,7 @@ run options = do
when (version options) $ do
putStrLn V.version
- exitWith ExitSuccess
+ exitSuccess
let repo = fromMaybe "." (repository options)
let entry = fromMaybe "main.json" (entrypoint options)
@@ -68,7 +66,7 @@ run options = do
Nothing -> error "Need a config file!"
Just path -> LB.readFile path >>= \res ->
case eitherDecode res :: Either String (LintConfig Identity) of
- Left err -> error $ "config file invalid: " <> err
+ Left err -> error $ "config file invalid: " <> toText err
Right file -> pure (patchConfig file (config options))
lints <- recursiveCheckDir lintconfig repo entry
@@ -79,16 +77,14 @@ run options = do
else printPretty (level, lints)
case out options of
- Nothing -> exitWith $ case resultIsFatal lintconfig lints of
- False -> ExitSuccess
- True -> ExitFailure 1
+ Nothing -> exitWith $ if resultIsFatal lintconfig lints then ExitFailure 1 else ExitSuccess
Just outpath -> do
c <- writeAdjustedRepository lintconfig repo outpath lints
unless (json options) $
case c of
- ExitFailure 1 -> putStrLn "\nMap failed linting!"
- ExitFailure 2 -> putStrLn "\nOutpath already exists, not writing anything."
- _ -> pure ()
+ ExitFailure 1 -> putTextLn "\nMap failed linting!"
+ ExitFailure 2 -> putTextLn "\nOutpath already exists, not writing anything."
+ _ -> pass
exitWith c
@@ -107,10 +103,10 @@ printLB a = T.putStrLn $ T.decodeUtf8 $ LB.toStrict a
aesonWarning :: IO ()
aesonWarning = case coercionToHashMap of
Just _ -> hPutStrLn stderr
- "Warning: this program was compiled using an older version of the Aeson Library\n\
+ ("Warning: this program was compiled using an older version of the Aeson Library\n\
\used for parsing JSON, which is susceptible to hash flooding attacks.\n\
\n\
\Recompiling with a newer version is recommended when handling untrusted inputs.\n\
\n\
- \See https://cs-syd.eu/posts/2021-09-11-json-vulnerability for details."
- _ -> pure ()
+ \See https://cs-syd.eu/posts/2021-09-11-json-vulnerability for details." :: Text)
+ _ -> pass
diff --git a/src/Version.hs b/src/Version.hs
index c0f7edf..2ec1537 100644
--- a/src/Version.hs
+++ b/src/Version.hs
@@ -3,10 +3,10 @@
module Version ( version ) where
-import Control.Monad.Trans (liftIO)
+import Universum
+
import qualified Language.Haskell.TH as TH
import System.Process (readProcess)
-import GHC.IO (catchAny)
version :: String
version = "walint rc3 2021 (" <>