on master help sign in
Fix HLint (#544)

Looks like the new version of hlint has a couple of new hints. changelog_begin changelog_end

commit9adb11125ed8c671e802405a272c5c34ec1df0d3 authorMoritz Kiefer <moritz.kiefer@purelyfunctional.org> dateSun 3 May 2020, 19:30 (6 years ago) parentcfcdf64
8 files changed+41−34
.gitignore+1 .hlint.yaml+2 src/Development/IDE/Core/Compile.hs+1−1 src/Development/IDE/Core/Rules.hs+2−3 src/Development/IDE/Core/Shake.hs+8−7 src/Development/IDE/LSP/Outline.hs+4−4 src/Development/IDE/Plugin/Completions/Logic.hs+2−2 test/exe/Main.hs+21−17
.gitignore+1
@@ -6,3 +6,4 @@ cabal.project.local
66*.lock
77/.tasty-rerun-log
88.vscode
9+/.hlint-*
.hlint.yaml+2
@@ -79,9 +79,11 @@
7979 - Development.IDE.Compat
8080 - Development.IDE.Core.FileStore
8181 - Development.IDE.Core.Compile
82+ - Development.IDE.Core.Rules
8283 - Development.IDE.GHC.Compat
8384 - Development.IDE.GHC.Util
8485 - Development.IDE.Import.FindImports
86+ - Development.IDE.LSP.Outline
8587 - Development.IDE.Spans.Calculate
8688 - Development.IDE.Spans.Documentation
8789 - Development.IDE.Spans.Common
src/Development/IDE/Core/Compile.hs+1−1
@@ -119,7 +119,7 @@ typecheckModule :: IdeDefer
119119 -> ParsedModule
120120 -> IO (IdeResult (HscEnv, TcModuleResult))
121121typecheckModule (IdeDefer defer) hsc depsIn pm = do
122− fmap (either (, Nothing) (second Just) . fmap sequence . sequence) $
122+ fmap (either (, Nothing) (second Just . sequence) . sequence) $
123123 runGhcEnv hsc $
124124 catchSrcErrors "typecheck" $ do
125125 -- Currently GetDependencies returns things in topological order so A comes before B if A imports B.
src/Development/IDE/Core/Rules.hs+2−3
@@ -5,7 +5,6 @@
55{-# LANGUAGE TypeFamilies #-}
66{-# LANGUAGE FlexibleInstances #-}
77{-# LANGUAGE DuplicateRecordFields #-}
8−{-# LANGUAGE PatternSynonyms #-}
98#include "ghc-api-version.h"
109
1110-- | A Shake implementation of the compiler service, built
@@ -150,7 +149,7 @@ getHomeHieFile f = do
150149 unless isUpToDate $
151150 void $ use_ TypeCheck f
152151
153− hf <- liftIO $ if isUpToDate then Just <$> loadHieFile hie_f else pure Nothing
152+ hf <- liftIO $ whenMaybe isUpToDate (loadHieFile hie_f)
154153 return ([], hf)
155154
156155getPackageHieFile :: Module -- ^ Package Module to load .hie file for
@@ -259,7 +258,7 @@ rawDependencyInformation f = do
259258 let initialArtifact = ArtifactsLocation f (ModLocation (Just $ fromNormalizedFilePath f) "" "") False
260259 (initialId, initialMap) = getPathId initialArtifact emptyPathIdMap
261260 (rdi, ss) <- go (IntSet.singleton $ getFilePathId initialId)
262− ((RawDependencyInformation IntMap.empty initialMap IntMap.empty), IntMap.empty)
261+ (RawDependencyInformation IntMap.empty initialMap IntMap.empty, IntMap.empty)
263262 let bm = IntMap.foldrWithKey (updateBootMap rdi) IntMap.empty ss
264263 return (rdi { rawBootMap = bm })
265264 where
src/Development/IDE/Core/Shake.hs+8−7
@@ -239,7 +239,6 @@ shakeRunDatabaseProfile mbProfileDir shakeDb acts = do
239239 shakeProfileDatabase shakeDb $ dir </> file
240240 return (dir </> file)
241241 return (res, proFile)
242− where
243242
244243{-# NOINLINE profileStartTime #-}
245244profileStartTime :: String
@@ -393,6 +392,8 @@ withMVar' var unmasked masked = mask $ \restore -> do
393392 pure c
394393
395394-- | Spawn immediately. If you are already inside a call to shakeRun that will be aborted with an exception.
395+{- HLINT ignore shakeRun "Redundant bracket" -}
396+-- HLint seems to get confused by type applications and suggests to remove parentheses.
396397shakeRun :: IdeState -> [Action a] -> IO (IO [a])
397398shakeRun IdeState{shakeExtras=ShakeExtras{..}, ..} acts =
398399 withMVar'
@@ -532,7 +533,7 @@ usesWithStale :: IdeRule k v
532533 => k -> [NormalizedFilePath] -> Action [Maybe (v, PositionMapping)]
533534usesWithStale key files = do
534535 values <- map (\(A value _) -> value) <$> apply (map (Q . (key,)) files)
535− mapM (uncurry lastValue) (zip files values)
536+ zipWithM lastValue files values
536537
537538
538539withProgress :: (Eq a, Hashable a) => Var (HMap.HashMap a Int) -> a -> Action b -> Action b
@@ -561,9 +562,9 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
561562 Just res -> return res
562563 Nothing -> do
563564 (bs, (diags, res)) <- actionCatch
564− (do v <- op key file; liftIO $ evaluate $ force $ v) $
565+ (do v <- op key file; liftIO $ evaluate $ force v) $
565566 \(e :: SomeException) -> pure (Nothing, ([ideErrorText file $ T.pack $ show e | not $ isBadDependency e],Nothing))
566− modTime <- liftIO $ join . fmap currentValue <$> getValues state GetModificationTime file
567+ modTime <- liftIO $ (currentValue =<<) <$> getValues state GetModificationTime file
567568 (bs, res) <- case res of
568569 Nothing -> do
569570 staleV <- liftIO $ getValues state key file
@@ -573,7 +574,7 @@ defineEarlyCutoff op = addBuiltinRule noLint noIdentity $ \(Q (key, file)) (old
573574 Succeeded ver v -> (toShakeValue ShakeStale bs, Stale ver v)
574575 Stale ver v -> (toShakeValue ShakeStale bs, Stale ver v)
575576 Failed -> (toShakeValue ShakeResult bs, Failed)
576− Just v -> pure $ (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
577+ Just v -> pure (maybe ShakeNoCutoff ShakeResult bs, Succeeded (vfsVersion =<< modTime) v)
577578 liftIO $ setValues state key file res
578579 updateFileDiagnostics file (Key key) extras $ map (\(_,y,z) -> (y,z)) diags
579580 let eq = case (bs, fmap decodeShakeValue old) of
@@ -700,7 +701,7 @@ updateFileDiagnostics ::
700701 -> [(ShowDiagnostic,Diagnostic)] -- ^ current results
701702 -> Action ()
702703updateFileDiagnostics fp k ShakeExtras{diagnostics, hiddenDiagnostics, publishedDiagnostics, state, debouncer, eventer} current = liftIO $ do
703− modTime <- join . fmap currentValue <$> getValues state GetModificationTime fp
704+ modTime <- (currentValue =<<) <$> getValues state GetModificationTime fp
704705 let (currentShown, currentHidden) = partition ((== ShowDiag) . fst) current
705706 mask_ $ do
706707 -- Mask async exceptions to ensure that updated diagnostics are always
@@ -713,7 +714,7 @@ updateFileDiagnostics fp k ShakeExtras{diagnostics, hiddenDiagnostics, published
713714 let newDiags = getFileDiagnostics fp newDiagsStore
714715 _ <- evaluate newDiagsStore
715716 _ <- evaluate newDiags
716− pure $! (newDiagsStore, newDiags)
717+ pure (newDiagsStore, newDiags)
717718 modifyVar_ hiddenDiagnostics $ \old -> do
718719 let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime)
719720 (T.pack $ show k) (map snd currentHidden) old
src/Development/IDE/LSP/Outline.hs+4−4
@@ -43,7 +43,7 @@ moduleOutline _lsp ideState DocumentSymbolParams { _textDocument = TextDocumentI
4343 mb_decls <- runAction ideState $ use GetParsedModule fp
4444 pure $ Right $ case mb_decls of
4545 Nothing -> DSDocumentSymbols (List [])
46− Just (ParsedModule { pm_parsed_source = L _ltop HsModule { hsmodName, hsmodDecls, hsmodImports } })
46+ Just ParsedModule { pm_parsed_source = L _ltop HsModule { hsmodName, hsmodDecls, hsmodImports } }
4747 -> let
4848 declSymbols = mapMaybe documentSymbolForDecl hsmodDecls
4949 moduleSymbol = hsmodName <&> \(L l m) ->
@@ -118,17 +118,17 @@ documentSymbolForDecl (L l (TyClD SynDecl { tcdLName = L l' n })) = Just
118118 , _kind = SkTypeParameter
119119 , _selectionRange = srcSpanToRange l'
120120 }
121−documentSymbolForDecl (L l (InstD (ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } })))
121+documentSymbolForDecl (L l (InstD ClsInstD { cid_inst = ClsInstDecl { cid_poly_ty } }))
122122 = Just (defDocumentSymbol l :: DocumentSymbol) { _name = pprText cid_poly_ty
123123 , _kind = SkInterface
124124 }
125−documentSymbolForDecl (L l (InstD DataFamInstD { dfid_inst = DataFamInstDecl (HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } }) }))
125+documentSymbolForDecl (L l (InstD DataFamInstD { dfid_inst = DataFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
126126 = Just (defDocumentSymbol l :: DocumentSymbol)
127127 { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords
128128 (map pprText feqn_pats)
129129 , _kind = SkInterface
130130 }
131−documentSymbolForDecl (L l (InstD TyFamInstD { tfid_inst = TyFamInstDecl (HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } }) }))
131+documentSymbolForDecl (L l (InstD TyFamInstD { tfid_inst = TyFamInstDecl HsIB { hsib_body = FamEqn { feqn_tycon, feqn_pats } } }))
132132 = Just (defDocumentSymbol l :: DocumentSymbol)
133133 { _name = showRdrName (unLoc feqn_tycon) <> " " <> T.unwords
134134 (map pprText feqn_pats)
src/Development/IDE/Plugin/Completions/Logic.hs+2−2
@@ -11,7 +11,7 @@ module Development.IDE.Plugin.Completions.Logic (
1111import Control.Applicative
1212import Data.Char (isSpace, isUpper)
1313import Data.Generics
14−import Data.List as List hiding (stripPrefix)
14+import Data.List.Extra as List hiding (stripPrefix)
1515import qualified Data.Map as Map
1616import Data.Maybe (fromMaybe, mapMaybe)
1717import qualified Data.Text as T
@@ -162,7 +162,7 @@ getArgText typ = argText
162162 where
163163 argTypes = getArgs typ
164164 argText :: T.Text
165− argText = mconcat $ List.intersperse " " $ zipWith snippet [1..] argTypes
165+ argText = mconcat $ List.intersperse " " $ zipWithFrom snippet 1 argTypes
166166 snippet :: Int -> Type -> T.Text
167167 snippet i t = T.pack $ "${" <> show i <> ":" <> showGhc t <> "}"
168168 getArgs :: Type -> [Type]
test/exe/Main.hs+21−17
@@ -14,9 +14,8 @@ import Control.Exception (catch)
1414import Control.Monad
1515import Control.Monad.IO.Class (liftIO)
1616import Data.Aeson (FromJSON, Value)
17−import Data.Char (toLower)
1817import Data.Foldable
19−import Data.List
18+import Data.List.Extra
2019import Data.Rope.UTF16 (Rope)
2120import qualified Data.Rope.UTF16 as Rope
2221import Development.IDE.Core.PositionMapping (fromCurrent, toCurrent)
@@ -129,8 +128,8 @@ initializeResponseTests = withResource acquire release tests where
129128 where
130129 doTest = do
131130 ir <- getInitializeResponse
132− let Just (ExecuteCommandOptions {_commands = List [command]}) = getActual $ innerCaps ir
133− True @=? (T.isSuffixOf "typesignature.add" command)
131+ let Just ExecuteCommandOptions {_commands = List [command]} = getActual $ innerCaps ir
132+ True @=? T.isSuffixOf "typesignature.add" command
134133
135134
136135 innerCaps :: InitializeResponse -> InitializeResponseCapabilitiesInner
@@ -401,14 +400,14 @@ diagnosticTests = testGroup "diagnostics"
401400 Just pathB <- pure $ uriToFilePath uriB
402401 uriB <- pure $
403402 let (drive, suffix) = splitDrive pathB
404− in filePathToUri (joinDrive (map toLower drive ) suffix)
403+ in filePathToUri (joinDrive (lower drive) suffix)
405404 liftIO $ createDirectoryIfMissing True (takeDirectory pathB)
406405 liftIO $ writeFileUTF8 pathB $ T.unpack bContent
407406 uriA <- getDocUri "A/A.hs"
408407 Just pathA <- pure $ uriToFilePath uriA
409408 uriA <- pure $
410409 let (drive, suffix) = splitDrive pathA
411− in filePathToUri (joinDrive (map toLower drive ) suffix)
410+ in filePathToUri (joinDrive (lower drive) suffix)
412411 let itemA = TextDocumentItem uriA "haskell" 0 aContent
413412 let a = TextDocumentIdentifier uriA
414413 sendNotification TextDocumentDidOpen (DidOpenTextDocumentParams itemA)
@@ -459,7 +458,7 @@ codeLensesTests = testGroup "code lenses"
459458watchedFilesTests :: TestTree
460459watchedFilesTests = testGroup "watched files"
461460 [ testSession' "workspace files" $ \sessionDir -> do
462− liftIO $ writeFile (sessionDir </> "hie.yaml") $ "cradle: {direct: {arguments: [\"-isrc\"]}}"
461+ liftIO $ writeFile (sessionDir </> "hie.yaml") "cradle: {direct: {arguments: [\"-isrc\"]}}"
463462 _doc <- openDoc' "A.hs" "haskell" "{-#LANGUAGE NoImplicitPrelude #-}\nmodule A where\nimport WatchedFilesMissingModule"
464463 watchedFileRegs <- getWatchedFilesSubscriptionsUntil @PublishDiagnosticsNotification
465464
@@ -473,7 +472,7 @@ watchedFilesTests = testGroup "watched files"
473472 liftIO $ length watchedFileRegs @?= 6
474473
475474 , testSession' "non workspace file" $ \sessionDir -> do
476− liftIO $ writeFile (sessionDir </> "hie.yaml") $ "cradle: {direct: {arguments: [\"-i/tmp\"]}}"
475+ liftIO $ writeFile (sessionDir </> "hie.yaml") "cradle: {direct: {arguments: [\"-i/tmp\"]}}"
477476 _doc <- openDoc' "A.hs" "haskell" "{-# LANGUAGE NoImplicitPrelude#-}\nmodule A where\nimport WatchedFilesMissingModule"
478477 watchedFileRegs <- getWatchedFilesSubscriptionsUntil @PublishDiagnosticsNotification
479478
@@ -980,14 +979,15 @@ suggestImportTests = testGroup "suggest import actions"
980979 let defLine = length imps + 1
981980 range = Range (Position defLine 0) (Position defLine maxBound)
982981 actions <- getCodeActions doc range
983− case wanted of
984− False ->
985− liftIO $ [_title | CACodeAction CodeAction{_title} <- actions, _title == newImp ] @?= []
986− True -> do
987− action <- liftIO $ pickActionWithTitle newImp actions
988− executeCodeAction action
989− contentAfterAction <- documentContents doc
990− liftIO $ after @=? contentAfterAction
982+ if wanted
983+ then do
984+ action <- liftIO $ pickActionWithTitle newImp actions
985+ executeCodeAction action
986+ contentAfterAction <- documentContents doc
987+ liftIO $ after @=? contentAfterAction
988+ else
989+ liftIO $ [_title | CACodeAction CodeAction{_title} <- actions, _title == newImp ] @?= []
990+
991991
992992addExtensionTests :: TestTree
993993addExtensionTests = testGroup "add language extension actions"
@@ -1984,6 +1984,8 @@ cradleTests = testGroup "cradle"
19841984 ,testGroup "loading" [loadCradleOnlyonce]
19851985 ]
19861986
1987+{- HLINT ignore loadCradleOnlyonce "Redundant bracket" -}
1988+-- HLint seems to get confused by type applications and suggests to remove parentheses.
19871989loadCradleOnlyonce :: TestTree
19881990loadCradleOnlyonce = testGroup "load cradle only once"
19891991 [ testSession' "implicit" implicit
@@ -2351,11 +2353,13 @@ nthLine i r
23512353 | i >= Rope.rows r = error $ "Row number out of bounds: " <> show i <> "/" <> show (Rope.rows r)
23522354 | otherwise = Rope.takeWhile (/= '\n') $ fst $ Rope.splitAtLine 1 $ snd $ Rope.splitAtLine (i - 1) r
23532355
2356+{- HLINT ignore getWatchedFilesSubscriptionsUntil "Redundant bracket" -}
2357+-- HLint seems to get confused by type applications and suggests to remove parentheses.
23542358getWatchedFilesSubscriptionsUntil :: forall end . (FromJSON end, Typeable end) => Session [Maybe Value]
23552359getWatchedFilesSubscriptionsUntil = do
23562360 msgs <- manyTill (Just <$> message @RegisterCapabilityRequest <|> Nothing <$ anyMessage) (message @end)
23572361 return
23582362 [ args
2359− | Just (RequestMessage{_params = RegistrationParams (List regs)}) <- msgs
2363+ | Just RequestMessage{_params = RegistrationParams (List regs)} <- msgs
23602364 , Registration _id WorkspaceDidChangeWatchedFiles args <- regs
23612365 ]