From 66ad857afedae1b24d985bad84c896955d965881 Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Fri, 26 Oct 2012 08:49:48 +0200 Subject: [PATCH] Fix a few issues found by newer hlint Testing with a newer hlint found a few minor issues; but all are real, valid recommendations: - don't use "if cond then f x else f y", but "f (if cond then x else y)" - "if a then b else True" is equivalent to the simpler "not a || b" - and as usual, one more ignore to our "testing basic properties" module Signed-off-by: Iustin Pop <iustin@google.com> Reviewed-by: Michael Hanselmann <hansmi@google.com> --- htest/Test/Ganeti/BasicTypes.hs | 1 + htest/Test/Ganeti/HTools/Loader.hs | 4 +--- htools/Ganeti/HTools/Cluster.hs | 10 +++++----- htools/Ganeti/HTools/Program/Hcheck.hs | 12 ++++++------ htools/Ganeti/Luxi.hs | 6 +++--- 5 files changed, 16 insertions(+), 17 deletions(-) diff --git a/htest/Test/Ganeti/BasicTypes.hs b/htest/Test/Ganeti/BasicTypes.hs index 1eab1259c..a74bc299c 100644 --- a/htest/Test/Ganeti/BasicTypes.hs +++ b/htest/Test/Ganeti/BasicTypes.hs @@ -45,6 +45,7 @@ import Ganeti.BasicTypes {-# ANN module "HLint: ignore Monad law, left identity" #-} {-# ANN module "HLint: ignore Monad law, right identity" #-} {-# ANN module "HLint: ignore Use >=>" #-} +{-# ANN module "HLint: ignore Use ." #-} -- * Arbitrary instances diff --git a/htest/Test/Ganeti/HTools/Loader.hs b/htest/Test/Ganeti/HTools/Loader.hs index a96aff5b3..e825f2bd4 100644 --- a/htest/Test/Ganeti/HTools/Loader.hs +++ b/htest/Test/Ganeti/HTools/Loader.hs @@ -64,9 +64,7 @@ prop_assignIndices = Loader.assignIndices (map (\n -> (Node.name n, n)) nodes) in Map.size nassoc == length nodes && Container.size kt == length nodes && - if not (null nodes) - then maximum (IntMap.keys kt) == length nodes - 1 - else True + (null nodes || maximum (IntMap.keys kt) == length nodes - 1) -- | Checks that the number of primary instances recorded on the nodes -- is zero. diff --git a/htools/Ganeti/HTools/Cluster.hs b/htools/Ganeti/HTools/Cluster.hs index 82d47574b..2f83e15a4 100644 --- a/htools/Ganeti/HTools/Cluster.hs +++ b/htools/Ganeti/HTools/Cluster.hs @@ -828,11 +828,11 @@ findBestAllocGroup mggl mgnl mgil allowed_gdxs inst cnt = goodSols = filterMGResults mggl sols sortedSols = sortMGResults mggl goodSols in if null sortedSols - then if null groups' - then Bad $ "no groups for evacuation: allowed groups was" ++ - show allowed_gdxs ++ ", all groups: " ++ - show (map fst groups) - else Bad $ intercalate ", " all_msgs + then Bad $ if null groups' + then "no groups for evacuation: allowed groups was" ++ + show allowed_gdxs ++ ", all groups: " ++ + show (map fst groups) + else intercalate ", " all_msgs else let (final_group, final_sol) = head sortedSols in return (final_group, final_sol, all_msgs) diff --git a/htools/Ganeti/HTools/Program/Hcheck.hs b/htools/Ganeti/HTools/Program/Hcheck.hs index f02b52adb..fb5909478 100644 --- a/htools/Ganeti/HTools/Program/Hcheck.hs +++ b/htools/Ganeti/HTools/Program/Hcheck.hs @@ -312,12 +312,12 @@ main opts args = do clusterstats = map sum . transpose . map snd $ groupsstats needrebalance = clusterNeedsRebalance clusterstats - unless (verbose == 0 || machineread) $ - if nosimulation - then putStrLn "Running in no-simulation mode." - else if needrebalance - then putStrLn "Cluster needs rebalancing." - else putStrLn "No need to rebalance cluster, no problems found." + unless (verbose == 0 || machineread) . + putStrLn $ if nosimulation + then "Running in no-simulation mode." + else if needrebalance + then "Cluster needs rebalancing." + else "No need to rebalance cluster, no problems found." mapM_ (printGroupStats verbose machineread Initial) groupsstats diff --git a/htools/Ganeti/Luxi.hs b/htools/Ganeti/Luxi.hs index 2086a0eef..92d77eb68 100644 --- a/htools/Ganeti/Luxi.hs +++ b/htools/Ganeti/Luxi.hs @@ -287,9 +287,9 @@ recvMsg s = do recvMsgExt :: Client -> IO RecvResult recvMsgExt s = catch (liftM RecvOk (recvMsg s)) $ \e -> - if isEOFError e - then return RecvConnClosed - else return $ RecvError (show e) + return $ if isEOFError e + then RecvConnClosed + else RecvError (show e) -- | Serialize a request to String. buildCall :: LuxiOp -- ^ The method -- GitLab