From 3986677b06e4d34c6fe9b2082ebf0a0eabf3ba29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Hr=C4=8Dek?= Date: Sun, 29 Aug 2021 14:50:49 +0200 Subject: [PATCH] Fix typos and simplify code --- lib/GHCup/Errors.hs | 2 +- lib/GHCup/Types.hs | 4 ++-- lib/GHCup/Types/JSON.hs | 2 +- lib/GHCup/Utils/Prelude.hs | 15 ++++----------- lib/GHCup/Utils/String/QQ.hs | 9 ++++----- test/GHCup/ArbitraryTypes.hs | 2 +- 6 files changed, 13 insertions(+), 21 deletions(-) diff --git a/lib/GHCup/Errors.hs b/lib/GHCup/Errors.hs index 7497b87..f29c223 100644 --- a/lib/GHCup/Errors.hs +++ b/lib/GHCup/Errors.hs @@ -50,7 +50,7 @@ instance Pretty NoCompatiblePlatform where pPrint (NoCompatiblePlatform str') = text ("Could not find a compatible platform. Got: " ++ str') --- | Unable to find a download for the requested versio/distro. +-- | Unable to find a download for the requested version/distro. data NoDownload = NoDownload deriving Show diff --git a/lib/GHCup/Types.hs b/lib/GHCup/Types.hs index b1dc66e..0ccf11c 100644 --- a/lib/GHCup/Types.hs +++ b/lib/GHCup/Types.hs @@ -152,7 +152,7 @@ data Tag = Latest | Recommended | Prerelease | Base PVP - | Old -- ^ old version are hidden by default in TUI + | Old -- ^ old versions are hidden by default in TUI | UnknownTag String -- ^ used for upwardscompat deriving (Ord, Eq, GHC.Generic, Show) -- FIXME: manual JSON instance @@ -241,7 +241,7 @@ instance NFData LinuxDistro distroToString :: LinuxDistro -> String distroToString Debian = "debian" distroToString Ubuntu = "ubuntu" -distroToString Mint= "mint" +distroToString Mint = "mint" distroToString Fedora = "fedora" distroToString CentOS = "centos" distroToString RedHat = "redhat" diff --git a/lib/GHCup/Types/JSON.hs b/lib/GHCup/Types/JSON.hs index 0d97f69..d10af4c 100644 --- a/lib/GHCup/Types/JSON.hs +++ b/lib/GHCup/Types/JSON.hs @@ -42,7 +42,7 @@ import qualified Text.Megaparsec as MP import qualified Text.Megaparsec.Char as MPC -deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } { fieldLabelModifier = removeLensFieldLabel } ''Architecture +deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''Architecture deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''LinuxDistro deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VSep deriveJSON defaultOptions { fieldLabelModifier = removeLensFieldLabel } ''VUnit diff --git a/lib/GHCup/Utils/Prelude.hs b/lib/GHCup/Utils/Prelude.hs index 20271b9..22f758d 100644 --- a/lib/GHCup/Utils/Prelude.hs +++ b/lib/GHCup/Utils/Prelude.hs @@ -75,7 +75,6 @@ import qualified System.Win32.File as Win32 -- >>> import Data.ByteString.Internal (c2w, w2c) -- >>> import Test.QuickCheck -- >>> import Data.Word8 --- >>> import Data.Word8 -- >>> import qualified Data.Text as T -- >>> instance Arbitrary T.Text where arbitrary = T.pack <$> arbitrary @@ -520,7 +519,7 @@ forFold :: (Foldable t, Applicative m, Monoid b) => t a -> (a -> m b) -> m b forFold = \t -> (`traverseFold` t) --- | Strip @\\r@ and @\\n@ from 'ByteString's +-- | Strip @\\r@ and @\\n@ from 'String's -- -- >>> stripNewline "foo\n\n\n" -- "foo" @@ -532,13 +531,10 @@ forFold = \t -> (`traverseFold` t) -- prop> \t -> stripNewline (t <> "\n") === stripNewline t -- prop> \t -> not (any (isNewLine . c2w) t) ==> stripNewline t == t stripNewline :: String -> String -stripNewline s - | null s = [] - | head s `elem` "\n\r" = stripNewline (tail s) - | otherwise = head s : stripNewline (tail s) +stripNewline = filter (`notElem` "\n\r") --- | Strip @\\r@ and @\\n@ from 'ByteString's +-- | Strip @\\r@ and @\\n@ from 'Text's -- -- >>> stripNewline' "foo\n\n\n" -- "foo" @@ -550,10 +546,7 @@ stripNewline s -- prop> \t -> stripNewline' (t <> "\n") === stripNewline' t -- prop> \t -> not (T.any (isNewLine . c2w) t) ==> stripNewline' t == t stripNewline' :: T.Text -> T.Text -stripNewline' s - | T.null s = mempty - | T.head s `elem` "\n\r" = stripNewline' (T.tail s) - | otherwise = T.singleton (T.head s) <> stripNewline' (T.tail s) +stripNewline' = T.filter (`notElem` "\n\r") -- | Is the word8 a newline? diff --git a/lib/GHCup/Utils/String/QQ.hs b/lib/GHCup/Utils/String/QQ.hs index a47bb41..dec56eb 100644 --- a/lib/GHCup/Utils/String/QQ.hs +++ b/lib/GHCup/Utils/String/QQ.hs @@ -44,15 +44,14 @@ import Language.Haskell.TH.Quote -- The pattern portion is undefined. s :: QuasiQuoter s = QuasiQuoter - (\s' -> case and $ fmap isAscii s' of + (\s' -> case all isAscii s' of True -> (\a -> [|fromString a|]) . trimLeadingNewline . removeCRs $ s' False -> fail "Not ascii" ) - (error "Cannot use q as a pattern") - (error "Cannot use q as a type") - (error "Cannot use q as a dec") + (error "Cannot use s as a pattern") + (error "Cannot use s as a type") + (error "Cannot use s as a dec") where removeCRs = filter (/= '\r') trimLeadingNewline ('\n' : xs) = xs trimLeadingNewline xs = xs - diff --git a/test/GHCup/ArbitraryTypes.hs b/test/GHCup/ArbitraryTypes.hs index 32fe5b4..eeba5a3 100644 --- a/test/GHCup/ArbitraryTypes.hs +++ b/test/GHCup/ArbitraryTypes.hs @@ -66,7 +66,7 @@ instance Arbitrary ByteString where --------------------- instance Arbitrary Scheme where - arbitrary = oneof [ pure (Scheme "http"), pure (Scheme "https") ] + arbitrary = elements [ Scheme "http", Scheme "https" ] instance Arbitrary Host where arbitrary = genericArbitrary