From bb8fe05db62347f4c1b3e00e9ef4c9268990dca6 Mon Sep 17 00:00:00 2001 From: Keagan McClelland Date: Mon, 23 May 2022 13:23:54 -0600 Subject: [PATCH] apply hint suggestions --- src/Foundation.hs | 7 +++---- src/Lib/PkgRepository.hs | 29 ++++++++++++++--------------- src/Lib/Types/AppIndex.hs | 2 +- src/Orphans/Cryptonite.hs | 2 +- 4 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/Foundation.hs b/src/Foundation.hs index 0dcffe3..deb1bbd 100644 --- a/src/Foundation.hs +++ b/src/Foundation.hs @@ -111,7 +111,7 @@ transitiveUpdate f = update (update @a @b f) setWebProcessThreadId :: (ThreadId, ThreadId) -> RegistryCtx -> IO () -setWebProcessThreadId tid a = putMVar (appWebServerThreadId a) $ tid +setWebProcessThreadId tid a = putMVar (appWebServerThreadId a) tid -- This is where we define all of the routes in our application. For a full -- explanation of the syntax, please see: @@ -173,11 +173,10 @@ instance Yesod RegistryCtx where <> str ) ) - <> (toLogStr + <> toLogStr (wrapSGRCode [SetColor Foreground Dull White] [i| @ #{loc_filename loc}:#{fst $ loc_start loc}\n|] ) - ) loggerPutStr logger formatted where renderLvl lvl = case lvl of @@ -242,4 +241,4 @@ unsafeHandler = Unsafe.fakeHandlerGetLogger appLogger -- https://github.com/yesodweb/yesod/wiki/i18n-messages-in-the-scaffolding appLogFunc :: RegistryCtx -> LogFunc -appLogFunc = appLogger >>= flip messageLoggerSource +appLogFunc = appLogger <**> messageLoggerSource diff --git a/src/Lib/PkgRepository.hs b/src/Lib/PkgRepository.hs index 9af8874..e60f32c 100644 --- a/src/Lib/PkgRepository.hs +++ b/src/Lib/PkgRepository.hs @@ -67,6 +67,7 @@ import Model import Startlude ( ($) , (&&) , (.) + , (/=) , (<$>) , Bool(..) , ByteString @@ -140,7 +141,7 @@ import Yesod.Core.Content ( typeGif ) import Yesod.Core.Types ( ContentType ) -data ManifestParseException = ManifestParseException FilePath +newtype ManifestParseException = ManifestParseException FilePath deriving Show instance Exception ManifestParseException @@ -149,7 +150,7 @@ data PkgRepo = PkgRepo , pkgRepoAppMgrBin :: FilePath } -data EosRepo = EosRepo +newtype EosRepo = EosRepo { eosRepoFileRoot :: FilePath } @@ -161,7 +162,7 @@ getVersionsFor pkg = do if exists then do subdirs <- listDirectory pkgDir - let (failures, successes) = partitionEithers $ (Atto.parseOnly parseVersion . T.pack) <$> subdirs + let (failures, successes) = partitionEithers $ Atto.parseOnly parseVersion . T.pack <$> subdirs for_ failures $ \f -> $logWarn [i|Emver Parse Failure for #{pkg}: #{f}|] pure successes else pure [] @@ -186,13 +187,11 @@ loadPkgDependencies appConnPool manifest = do let deps' = first PkgRecordKey <$> HM.toList deps for_ deps' - (\d -> - (runSqlPool - ( insertUnique - $ PkgDependency time (PkgRecordKey pkgId) pkgVersion (fst d) (packageDependencyVersion . snd $ d) - ) - appConnPool + (\d -> runSqlPool + ( insertUnique + $ PkgDependency time (PkgRecordKey pkgId) pkgVersion (fst d) (packageDependencyVersion . snd $ d) ) + appConnPool ) -- extract all package assets into their own respective files @@ -232,7 +231,7 @@ extractPkg pool fp = handle @_ @SomeException cleanup $ do $logError $ show e let pkgRoot = takeDirectory fp fs <- listDirectory pkgRoot - let toRemove = filter (not . (== ".s9pk") . takeExtension) fs + let toRemove = filter ((/=) ".s9pk" . takeExtension) fs mapConcurrently_ (removeFile . (pkgRoot )) toRemove throwIO e @@ -295,7 +294,7 @@ getManifest pkg version = do root <- asks pkgRepoFileRoot let manifestPath = root show pkg show version "manifest.json" n <- getFileSize manifestPath - pure $ (n, sourceFile manifestPath) + pure (n, sourceFile manifestPath) getInstructions :: (MonadResource m, MonadReader r m, Has PkgRepo r) => PkgId @@ -305,7 +304,7 @@ getInstructions pkg version = do root <- asks pkgRepoFileRoot let instructionsPath = root show pkg show version "instructions.md" n <- getFileSize instructionsPath - pure $ (n, sourceFile instructionsPath) + pure (n, sourceFile instructionsPath) getLicense :: (MonadResource m, MonadReader r m, Has PkgRepo r) => PkgId @@ -315,7 +314,7 @@ getLicense pkg version = do root <- asks pkgRepoFileRoot let licensePath = root show pkg show version "license.md" n <- getFileSize licensePath - pure $ (n, sourceFile licensePath) + pure (n, sourceFile licensePath) getIcon :: (MonadResource m, MonadReader r m, Has PkgRepo r) => PkgId @@ -326,7 +325,7 @@ getIcon pkg version = do let pkgRoot = root show pkg show version mIconFile <- find ((== "icon") . takeBaseName) <$> listDirectory pkgRoot case mIconFile of - Nothing -> throwIO $ NotFoundE $ [i|#{pkg}: Icon|] + Nothing -> throwIO $ NotFoundE [i|#{pkg}: Icon|] Just x -> do let ct = case takeExtension x of ".png" -> typePng @@ -336,7 +335,7 @@ getIcon pkg version = do ".gif" -> typeGif _ -> typePlain n <- getFileSize (pkgRoot x) - pure $ (ct, n, sourceFile (pkgRoot x)) + pure (ct, n, sourceFile (pkgRoot x)) getHash :: (MonadIO m, MonadReader r m, Has PkgRepo r) => PkgId -> Version -> m ByteString getHash pkg version = do diff --git a/src/Lib/Types/AppIndex.hs b/src/Lib/Types/AppIndex.hs index 363b635..9e575e8 100644 --- a/src/Lib/Types/AppIndex.hs +++ b/src/Lib/Types/AppIndex.hs @@ -61,7 +61,7 @@ instance ToJSONKey PkgId where instance PersistField PkgId where toPersistValue = PersistText . show fromPersistValue (PersistText t) = Right . PkgId $ toS t - fromPersistValue other = Left $ [i|Invalid AppId: #{other}|] + fromPersistValue other = Left [i|Invalid AppId: #{other}|] instance PersistFieldSql PkgId where sqlType _ = SqlString instance PathPiece PkgId where diff --git a/src/Orphans/Cryptonite.hs b/src/Orphans/Cryptonite.hs index 66e57ab..21fada7 100644 --- a/src/Orphans/Cryptonite.hs +++ b/src/Orphans/Cryptonite.hs @@ -17,10 +17,10 @@ import Database.Persist ( PersistField(..) import Database.Persist.Sql ( PersistFieldSql(..) ) import Startlude ( ($) , (.) - , Bifunctor(bimap, first) , ByteString , Either(Left) , Semigroup((<>)) + , bimap , decodeUtf8 , encodeUtf8 , join