From beecb3c9ac70056d623c4c490cec4149b7d05ef4 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Mon, 16 Aug 2021 14:25:18 +1000 Subject: [PATCH] cln: hlint: Clean up list related hlint warnings. --- .hlint.yaml | 6 ------ Shake.hs | 8 +++----- hledger-lib/Hledger/Data/RawOptions.hs | 2 +- hledger-lib/Hledger/Utils/Debug.hs | 16 ++++++++-------- hledger-ui/Hledger/UI/AccountsScreen.hs | 2 +- hledger/Hledger/Cli/Commands/Balance.hs | 2 +- hledger/Hledger/Cli/Main.hs | 2 +- hledger/Hledger/Cli/Version.hs | 12 ++++++------ tools/simplifyprof.hs | 2 +- 9 files changed, 22 insertions(+), 30 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index a7f31d9f9..9602c31cb 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -7,8 +7,6 @@ # Warnings currently triggered by your code -- ignore: {name: "Use ++"} -- ignore: {name: "Use list literal"} - ignore: {name: "Move brackets to avoid $"} - ignore: {name: "Redundant $"} - ignore: {name: "Use <$>"} @@ -24,17 +22,13 @@ - ignore: {name: "Use camelCase"} - ignore: {name: "Use list comprehension"} - ignore: {name: "Redundant <$>"} -- ignore: {name: "Use list literal pattern"} - ignore: {name: "Use fewer imports"} - ignore: {name: "Use tuple-section"} - ignore: {name: "Use section"} - ignore: {name: "Avoid lambda using `infix`"} - ignore: {name: "Functor law"} - ignore: {name: "Missing NOINLINE pragma"} -- ignore: {name: "Use dropWhile"} -- ignore: {name: "Use replicate"} - ignore: {name: "Use void"} -- ignore: {name: "Use elemIndex"} - ignore: {name: "Use lambda-case"} diff --git a/Shake.hs b/Shake.hs index 1f5951e4b..1009b7ed1 100755 --- a/Shake.hs +++ b/Shake.hs @@ -299,10 +299,8 @@ main = do Nothing -> return () -- update "source" files depending on .version in the specified packages - let dependents = concat [ - map ( ".version.m4") specifiedpkgs - ,map ( "package.yaml") specifiedpkgs - ] + let dependents = map ( ".version.m4") specifiedpkgs + ++ map ( "package.yaml") specifiedpkgs need dependents -- and maybe commit them @@ -333,7 +331,7 @@ main = do need [versionfile] version <- ((head . words) <$>) $ liftIO $ readFile versionfile let ma:jor:_ = splitOn "." version - nextmajorversion = intercalate "." $ ma : (show $ read jor+1) : [] + nextmajorversion = intercalate "." [ma, show $ read jor+1] -- One simple task: update some strings in a small text file. -- Several ugly solutions: diff --git a/hledger-lib/Hledger/Data/RawOptions.hs b/hledger-lib/Hledger/Data/RawOptions.hs index 0a6438438..9f2e8fcc7 100644 --- a/hledger-lib/Hledger/Data/RawOptions.hs +++ b/hledger-lib/Hledger/Data/RawOptions.hs @@ -50,7 +50,7 @@ setboolopt :: String -> RawOpts -> RawOpts setboolopt name = overRawOpts (++ [(name,"")]) appendopts :: [(String,String)] -> RawOpts -> RawOpts -appendopts new = overRawOpts $ \old -> concat [old,new] +appendopts new = overRawOpts (++new) -- | Is the named option present ? inRawOpts :: String -> RawOpts -> Bool diff --git a/hledger-lib/Hledger/Utils/Debug.hs b/hledger-lib/Hledger/Utils/Debug.hs index 5250d61f6..c4f771afd 100644 --- a/hledger-lib/Hledger/Utils/Debug.hs +++ b/hledger-lib/Hledger/Utils/Debug.hs @@ -154,8 +154,8 @@ traceWith f a = trace (f a) a -- {-# NOINLINE debugLevel #-} -- Avoid using dbg* in this function (infinite loop). debugLevel :: Int -debugLevel = case snd $ break (=="--debug") args of - "--debug":[] -> 1 +debugLevel = case dropWhile (/="--debug") args of + ["--debug"] -> 1 "--debug":n:_ -> readDef 1 n _ -> case take 1 $ filter ("--debug" `isPrefixOf`) args of @@ -215,7 +215,7 @@ colorOption :: String colorOption = -- similar to debugLevel let args = unsafePerformIO getArgs in - case snd $ break (=="--color") args of + case dropWhile (/="--color") args of -- --color ARG "--color":v:_ -> v _ -> @@ -223,7 +223,7 @@ colorOption = -- --color=ARG ['-':'-':'c':'o':'l':'o':'r':'=':v] -> v _ -> - case snd $ break (=="--colour") args of + case dropWhile (/="--colour") args of -- --colour ARG "--colour":v:_ -> v _ -> @@ -250,13 +250,13 @@ hasOutputFile = outputFileOption `notElem` [Nothing, Just "-"] outputFileOption :: Maybe String outputFileOption = let args = unsafePerformIO getArgs in - case snd $ break ("-o" `isPrefixOf`) args of + case dropWhile (not . ("-o" `isPrefixOf`)) args of -- -oARG ('-':'o':v@(_:_)):_ -> Just v -- -o ARG "-o":v:_ -> Just v _ -> - case snd $ break (=="--output-file") args of + case dropWhile (/="--output-file") args of -- --output-file ARG "--output-file":v:_ -> Just v _ -> @@ -288,8 +288,8 @@ ptraceAt level | otherwise = \s a -> let p = pshow a ls = lines p nlorspace | length ls > 1 = "\n" - | otherwise = " " ++ take (10 - length s) (repeat ' ') - ls' | length ls > 1 = map (" "++) ls + | otherwise = replicate (11 - length s) ' ' + ls' | length ls > 1 = map (' ':) ls | otherwise = ls in trace (s++":"++nlorspace++intercalate "\n" ls') a diff --git a/hledger-ui/Hledger/UI/AccountsScreen.hs b/hledger-ui/Hledger/UI/AccountsScreen.hs index 56443da57..fadf3ff3a 100644 --- a/hledger-ui/Hledger/UI/AccountsScreen.hs +++ b/hledger-ui/Hledger/UI/AccountsScreen.hs @@ -69,7 +69,7 @@ asInit d reset ui@UIState{ (_, Nothing) -> 0 (_, Just (_,AccountsScreenItem{asItemAccountName=a})) -> headDef 0 $ catMaybes [ - findIndex (a ==) as + elemIndex a as ,findIndex (a `isAccountNamePrefixOf`) as ,Just $ max 0 (length (filter (< a) as) - 1) ] diff --git a/hledger/Hledger/Cli/Commands/Balance.hs b/hledger/Hledger/Cli/Commands/Balance.hs index 68dd3fe12..fab672acc 100644 --- a/hledger/Hledger/Cli/Commands/Balance.hs +++ b/hledger/Hledger/Cli/Commands/Balance.hs @@ -397,7 +397,7 @@ balance opts@CliOpts{reportspec_=rspec} j = case balancecalc_ of -- | Render a single-column balance report as CSV. balanceReportAsCsv :: ReportOpts -> BalanceReport -> CSV balanceReportAsCsv opts (items, total) = - ("account" : ((if commodity_column_ opts then (:) "commodity" else id) $ "balance" : [])) + ("account" : ((if commodity_column_ opts then (:) "commodity" else id) $ ["balance"])) : (concatMap (\(a, _, _, b) -> rows a b) items) ++ if no_total_ opts then [] else rows "total" total where diff --git a/hledger/Hledger/Cli/Main.hs b/hledger/Hledger/Cli/Main.hs index edfd13f2d..1a94e1539 100644 --- a/hledger/Hledger/Cli/Main.hs +++ b/hledger/Hledger/Cli/Main.hs @@ -229,7 +229,7 @@ moveFlagsAfterCommand args = moveArgs $ ensureDebugHasArg args ensureDebugHasArg as = case break (=="--debug") as of (bs,"--debug":c:cs) | null c || not (all isDigit c) -> bs++"--debug=1":c:cs - (bs,"--debug":[]) -> bs++"--debug=1":[] + (bs,["--debug"]) -> bs++["--debug=1"] _ -> as moveArgs args = insertFlagsAfterCommand $ moveArgs' (args, []) diff --git a/hledger/Hledger/Cli/Version.hs b/hledger/Hledger/Cli/Version.hs index 47d18b364..102a4bd67 100644 --- a/hledger/Hledger/Cli/Version.hs +++ b/hledger/Hledger/Cli/Version.hs @@ -41,16 +41,16 @@ patchlevel = "" buildversion :: String buildversion = prettify . splitAtElement '.' $ packageversion ++ patchlevel where - prettify (major:minor:bugfix:patches:[]) = + prettify [major,minor,bugfix,patches] = major ++ "." ++ minor ++ bugfix' ++ patches' where bugfix' = if bugfix == "0" then "" else '.' : bugfix patches' = if patches == "0" then "" else '+' : patches - prettify (major:minor:bugfix:[]) = prettify [major,minor,bugfix,"0"] - prettify (major:minor:[]) = prettify [major,minor,"0","0"] - prettify (major:[]) = prettify [major,"0","0","0"] - prettify [] = error' "VERSION is empty, please fix" -- PARTIAL: - prettify _ = error' "VERSION has too many components, please fix" + prettify [major,minor,bugfix] = prettify [major,minor,bugfix,"0"] + prettify [major,minor] = prettify [major,minor,"0","0"] + prettify [major] = prettify [major,"0","0","0"] + prettify [] = error' "VERSION is empty, please fix" -- PARTIAL: + prettify _ = error' "VERSION has too many components, please fix" -- | The name of this package's main executable. progname :: String diff --git a/tools/simplifyprof.hs b/tools/simplifyprof.hs index 10b369912..791617b2e 100755 --- a/tools/simplifyprof.hs +++ b/tools/simplifyprof.hs @@ -30,4 +30,4 @@ getfields s = name:rest showheading fmt = format fmt ["cost centre","entries","%time","%alloc","%time-inh","%alloc-inh"] -format fmt (s1:s2:s3:s4:s5:s6:[]) = printf fmt s1 s2 s3 s4 s5 s6 +format fmt [s1,s2,s3,s4,s5,s6] = printf fmt s1 s2 s3 s4 s5 s6