From 21e62ffcbdeba57b2beb8f1e8b24560f833cdc37 Mon Sep 17 00:00:00 2001 From: Stephen Morgan Date: Mon, 16 Aug 2021 14:57:15 +1000 Subject: [PATCH] cln: hlint: Remove unless and $> warnings. --- .hlint.yaml | 2 -- bin/hledger-check-fancyassertions.hs | 3 ++- bin/hledger-check-tagfiles.cabal.hs | 2 +- bin/hledger-check-tagfiles.hs | 2 +- hledger-lib/Hledger/Data/Dates.hs | 3 ++- hledger-lib/Hledger/Data/Journal.hs | 2 +- hledger-lib/Hledger/Read.hs | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.hlint.yaml b/.hlint.yaml index 9602c31cb..3746cb1c3 100644 --- a/.hlint.yaml +++ b/.hlint.yaml @@ -13,8 +13,6 @@ - ignore: {name: "Redundant bracket"} - ignore: {name: "Avoid reverse"} - ignore: {name: "Eta reduce"} -- ignore: {name: "Use $>"} -- ignore: {name: "Use unless"} - ignore: {name: "Use =<<"} - ignore: {name: "Use fmap"} - ignore: {name: "Use <&>"} diff --git a/bin/hledger-check-fancyassertions.hs b/bin/hledger-check-fancyassertions.hs index 9c88a261a..57c6a8a6c 100755 --- a/bin/hledger-check-fancyassertions.hs +++ b/bin/hledger-check-fancyassertions.hs @@ -102,6 +102,7 @@ import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.State.Strict (runStateT) import Data.String (fromString) import Data.Function (on) +import Data.Functor (($>)) import Data.Functor.Identity (Identity(..)) import Data.List (foldl', groupBy, intercalate, nub, sortOn) import Data.List.NonEmpty (NonEmpty(..), nonEmpty, toList) @@ -493,5 +494,5 @@ sameish f = (==) `on` f . toGregorian . H.postingDate -- | Helper for 'Compare' and 'Connect' parsers. gostringsp :: Monad m => [(String, a)] -> H.TextParser m a -gostringsp ((s,a):rest) = P.try (P.string (fromString s) *> pure a) `mplus` gostringsp rest +gostringsp ((s,a):rest) = P.try (P.string (fromString s) $> a) `mplus` gostringsp rest gostringsp [] = mzero diff --git a/bin/hledger-check-tagfiles.cabal.hs b/bin/hledger-check-tagfiles.cabal.hs index 7070ce059..5ce3f0225 100755 --- a/bin/hledger-check-tagfiles.cabal.hs +++ b/bin/hledger-check-tagfiles.cabal.hs @@ -30,6 +30,6 @@ main = withJournalDo defcliopts $ \j -> do ] forM_ filetags $ \(t,f) -> do exists <- doesFileExist f - when (not exists) $ do + unless exists $ do putStrLn $ "file not found in tag: " ++ t ++ ": " ++ f exitFailure diff --git a/bin/hledger-check-tagfiles.hs b/bin/hledger-check-tagfiles.hs index c074b92fe..a51be9717 100755 --- a/bin/hledger-check-tagfiles.hs +++ b/bin/hledger-check-tagfiles.hs @@ -31,6 +31,6 @@ main = withJournalDo defcliopts $ \j -> do ] forM_ filetags $ \(t,f) -> do exists <- doesFileExist f - when (not exists) $ do + unless exists $ do putStrLn $ "file not found in tag: " ++ t ++ ": " ++ f exitFailure diff --git a/hledger-lib/Hledger/Data/Dates.hs b/hledger-lib/Hledger/Data/Dates.hs index 9236d783d..b4126b475 100644 --- a/hledger-lib/Hledger/Data/Dates.hs +++ b/hledger-lib/Hledger/Data/Dates.hs @@ -89,6 +89,7 @@ import Data.Char (digitToInt, isDigit, ord) import Data.Default import Data.Foldable (asum) import Data.Function (on) +import Data.Functor (($>)) import Data.Maybe import qualified Data.Set as Set import Data.Text (Text) @@ -776,7 +777,7 @@ validMonth n = n >= 1 && n <= 12 validDay n = n >= 1 && n <= 31 failIfInvalidDate :: Fail.MonadFail m => SmartDate -> m SmartDate -failIfInvalidDate s = unless isValid (Fail.fail $ "bad smart date: " ++ show s) *> return s +failIfInvalidDate s = unless isValid (Fail.fail $ "bad smart date: " ++ show s) $> s where isValid = case s of SmartAssumeStart y (Just (m, md)) -> isJust $ fromGregorianValid y m (fromMaybe 1 md) SmartFromReference mm d -> isJust $ fromGregorianValid 2004 (fromMaybe 1 mm) d diff --git a/hledger-lib/Hledger/Data/Journal.hs b/hledger-lib/Hledger/Data/Journal.hs index 3e2e6c18e..414f71042 100644 --- a/hledger-lib/Hledger/Data/Journal.hs +++ b/hledger-lib/Hledger/Data/Journal.hs @@ -1013,7 +1013,7 @@ checkBalanceAssertionOneCommodityB p@Posting{paccount=assertedacct} assertedamt -- (showAmount assertedamt) (show $ aquantity assertedamt - aquantity actualbalincomm) - when (not pass) $ throwError errmsg + unless pass $ throwError errmsg -- | Throw an error if this posting is trying to do an illegal balance assignment. checkIllegalBalanceAssignmentB :: Posting -> Balancing s () diff --git a/hledger-lib/Hledger/Read.hs b/hledger-lib/Hledger/Read.hs index bda6c194e..51ad837fc 100644 --- a/hledger-lib/Hledger/Read.hs +++ b/hledger-lib/Hledger/Read.hs @@ -46,7 +46,7 @@ module Hledger.Read ( --- ** imports import Control.Arrow (right) import qualified Control.Exception as C -import Control.Monad (when) +import Control.Monad (unless, when) import "mtl" Control.Monad.Except (runExceptT) import Data.Default (def) import Data.Foldable (asum) @@ -192,7 +192,7 @@ requireJournalFileExists :: FilePath -> IO () requireJournalFileExists "-" = return () requireJournalFileExists f = do exists <- doesFileExist f - when (not exists) $ do -- XXX might not be a journal file + unless exists $ do -- XXX might not be a journal file hPutStr stderr $ "The hledger journal file \"" <> f <> "\" was not found.\n" hPutStr stderr "Please create it first, eg with \"hledger add\" or a text editor.\n" hPutStr stderr "Or, specify an existing journal file with -f or LEDGER_FILE.\n" @@ -207,7 +207,7 @@ ensureJournalFileExists f = do hPutStr stderr $ "Part of file path \"" <> show f <> "\"\n ends with a dot, which is unsafe on Windows; please use a different path.\n" exitFailure exists <- doesFileExist f - when (not exists) $ do + unless exists $ do hPutStr stderr $ "Creating hledger journal file " <> show f <> ".\n" -- note Hledger.Utils.UTF8.* do no line ending conversion on windows, -- we currently require unix line endings on all platforms.