hlint 3.0.3 → 3.0.4
raw patch · 28 files changed
+129/−139 lines, 28 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.txt +3/−0
- hlint.cabal +1/−2
- src/Config/Compute.hs +1/−0
- src/Config/Haskell.hs +4/−3
- src/Config/Yaml.hs +12/−12
- src/Extension.hs +0/−1
- src/GHC/Util.hs +6/−17
- src/GHC/Util/HsExpr.hs +1/−1
- src/GHC/Util/Outputable.hs +0/−14
- src/GHC/Util/Scope.hs +2/−1
- src/GHC/Util/Unify.hs +3/−3
- src/HSE/All.hs +49/−51
- src/Hint/Bracket.hs +2/−0
- src/Hint/Duplicate.hs +1/−0
- src/Hint/Extensions.hs +1/−0
- src/Hint/Import.hs +3/−1
- src/Hint/Lambda.hs +1/−1
- src/Hint/List.hs +1/−0
- src/Hint/ListRec.hs +1/−0
- src/Hint/Match.hs +1/−0
- src/Hint/Monad.hs +1/−0
- src/Hint/Naming.hs +1/−0
- src/Hint/Pattern.hs +1/−0
- src/Hint/Smell.hs +1/−1
- src/Hint/Unsafe.hs +1/−1
- src/Idea.hs +24/−22
- src/Test/All.hs +1/−1
- src/Test/Annotations.hs +6/−7
CHANGES.txt view
@@ -1,5 +1,8 @@ Changelog for HLint (* = breaking change) +3.0.4, released 2020-05-03+ #968, fail on all parse errors+ #967, enable TypeApplications by default 3.0.3, released 2020-05-03 #965, fix incorrect avoid lambda suggestion 3.0.2, released 2020-05-03
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version: >= 1.18 build-type: Simple name: hlint-version: 3.0.3+version: 3.0.4 license: BSD3 license-file: LICENSE category: Development@@ -117,7 +117,6 @@ GHC.Util.HsDecl GHC.Util.HsExpr GHC.Util.Module- GHC.Util.Outputable GHC.Util.SrcLoc GHC.Util.DynFlags GHC.Util.RdrName
src/Config/Compute.hs view
@@ -15,6 +15,7 @@ import Bag import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances import Language.Haskell.GhclibParserEx.GHC.Hs.Expr+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import SrcLoc import Prelude
src/Config/Haskell.hs view
@@ -15,7 +15,7 @@ import GHC.Util -import SrcLoc as GHC+import SrcLoc import GHC.Hs.Extension import GHC.Hs.Decls hiding (SpliceDecl) import GHC.Hs.Expr hiding (Match)@@ -25,6 +25,7 @@ import OccName import Outputable +import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable -- | Read an {-# ANN #-} pragma and determine if it is intended for HLint. -- Return Nothing if it is not an HLint pragma, otherwise what it means.@@ -46,7 +47,7 @@ f _ = Nothing readPragma _ = Nothing -readComment :: GHC.Located AnnotationComment -> [Classify]+readComment :: Located AnnotationComment -> [Classify] readComment c@(L pos AnnBlockComment{}) | (hash, x) <- maybe (False, x) (True,) $ stripPrefix "#" x , x <- trim x@@ -79,7 +80,7 @@ ": Error while reading hint file, " ++ msg ++ "\n" ++ unsafePrettyPrint val -errorOnComment :: GHC.Located AnnotationComment -> String -> b+errorOnComment :: Located AnnotationComment -> String -> b errorOnComment c@(L s _) msg = exitMessageImpure $ let isMultiline = isCommentMultiline c in showSrcSpan' s ++
src/Config/Yaml.hs view
@@ -30,13 +30,13 @@ import Prelude import Bag-import qualified Lexer as GHC-import qualified ErrUtils-import qualified Outputable+import Lexer+import ErrUtils hiding (Severity)+import Outputable import GHC.Hs import SrcLoc-import qualified RdrName as GHC-import qualified OccName as GHC+import RdrName+import OccName import GHC.Util (baseDynFlags, Scope,scopeCreate) import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances import Data.Char@@ -161,13 +161,13 @@ when (bad /= []) $ parseFail v $ "Not allowed keys: " ++ unwords bad -parseGHC :: (ParseFlags -> String -> GHC.ParseResult v) -> Val -> Parser v+parseGHC :: (ParseFlags -> String -> ParseResult v) -> Val -> Parser v parseGHC parser v = do x <- parseString v case parser defaultParseFlags{extensions=configExtensions} x of- GHC.POk _ x -> pure x- GHC.PFailed ps ->- let (_, errs) = GHC.getMessages ps baseDynFlags+ POk _ x -> pure x+ PFailed ps ->+ let (_, errs) = getMessages ps baseDynFlags errMsg = head (bagToList errs) msg = Outputable.showSDoc baseDynFlags $ ErrUtils.pprLocErrMsg errMsg in parseFail v $ "Failed to parse " ++ msg ++ ", when parsing:\n " ++ x@@ -277,8 +277,8 @@ parseWithin v = do x <- parseGHC parseExpGhcWithMode v case x of- L _ (HsVar _ (L _ (GHC.Unqual x))) -> pure $ f "" (GHC.occNameString x)- L _ (HsVar _ (L _ (GHC.Qual mod x))) -> pure $ f (moduleNameString mod) (GHC.occNameString x)+ L _ (HsVar _ (L _ (Unqual x))) -> pure $ f "" (occNameString x)+ L _ (HsVar _ (L _ (Qual mod x))) -> pure $ f (moduleNameString mod) (occNameString x) _ -> parseFail v "Bad classification rule" where f mod name@(c:_) | isUpper c = [(mod,name),(mod ++ ['.' | mod /= ""] ++ name, "")]@@ -300,7 +300,7 @@ where (ls, rs) = both f (lhs, rhs) f :: LHsExpr GhcPs -> [String]- f x = [y | L _ (HsVar _ (L _ x)) <- universe x, let y = GHC.occNameString $ GHC.rdrNameOcc x, not $ isUnifyVar y, y /= "."]+ f x = [y | L _ (HsVar _ (L _ x)) <- universe x, let y = occNameString $ rdrNameOcc x, not $ isUnifyVar y, y /= "."] asNote :: String -> Note
src/Extension.hs view
@@ -16,7 +16,6 @@ , UnboxedTuples, UnboxedSums -- breaks (#) lens operator , QuasiQuotes -- breaks [x| ...], making whitespace free list comps break , {- DoRec , -} RecursiveDo -- breaks rec- , TypeApplications -- HSE fails on @ patterns ] reallyBadExtensions =
src/GHC/Util.hs view
@@ -8,15 +8,13 @@ , module GHC.Util.HsDecl , module GHC.Util.HsExpr , module GHC.Util.Module- , module GHC.Util.Outputable , module GHC.Util.SrcLoc , module GHC.Util.DynFlags , module GHC.Util.Scope , module GHC.Util.RdrName , module GHC.Util.Unify- , parsePragmasIntoDynFlags- , parseFileGhcLib, parseExpGhcLib, parseImportGhcLib, parseDeclGhcLib+ , fileToModule , pattern SrcSpan, srcSpanFilename, srcSpanStartLine', srcSpanStartColumn, srcSpanEndLine', srcSpanEndColumn , pattern SrcLoc, srcFilename, srcLine, srcColumn , showSrcSpan',@@ -28,15 +26,15 @@ import GHC.Util.HsExpr import GHC.Util.HsDecl import GHC.Util.Module-import GHC.Util.Outputable import GHC.Util.SrcLoc import GHC.Util.DynFlags import GHC.Util.RdrName import GHC.Util.Scope import GHC.Util.Unify -import qualified Language.Haskell.GhclibParserEx.GHC.Parser as GhclibParserEx+import Language.Haskell.GhclibParserEx.GHC.Parser (parseFile) import Language.Haskell.GhclibParserEx.GHC.Driver.Session (parsePragmasIntoDynFlags)+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import GHC.Hs import Lexer@@ -47,18 +45,9 @@ import System.FilePath import Language.Preprocessor.Unlit -parseExpGhcLib :: String -> DynFlags -> ParseResult (LHsExpr GhcPs)-parseExpGhcLib = GhclibParserEx.parseExpression--parseImportGhcLib :: String -> DynFlags -> ParseResult (LImportDecl GhcPs)-parseImportGhcLib = GhclibParserEx.parseImport--parseDeclGhcLib :: String -> DynFlags -> ParseResult (LHsDecl GhcPs)-parseDeclGhcLib = GhclibParserEx.parseDeclaration--parseFileGhcLib :: FilePath -> String -> DynFlags -> ParseResult (Located (HsModule GhcPs))-parseFileGhcLib filename str flags =- GhclibParserEx.parseFile filename flags+fileToModule :: FilePath -> String -> DynFlags -> ParseResult (Located (HsModule GhcPs))+fileToModule filename str flags =+ parseFile filename flags (if takeExtension filename /= ".lhs" then str else unlit filename str) {-# COMPLETE SrcSpan #-}
src/GHC/Util/HsExpr.hs view
@@ -24,7 +24,6 @@ import GHC.Util.Brackets import GHC.Util.View import GHC.Util.FreeVars-import GHC.Util.Outputable (unsafePrettyPrint) import Control.Applicative import Control.Monad.Trans.State@@ -41,6 +40,7 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.Pat import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable -- | 'dotApp a b' makes 'a . b'. dotApp' :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs
− src/GHC/Util/Outputable.hs
@@ -1,14 +0,0 @@--module GHC.Util.Outputable (unsafePrettyPrint) where--import Outputable---- \"Unsafe\" in this case means that it uses the following--- 'DynFlags' for printing ---- <http://hackage.haskell.org/package/ghc-lib-parser-8.8.0.20190424/docs/src/DynFlags.html#v_unsafeGlobalDynFlags--- unsafeGlobalDynFlags> This could lead to the issues documented--- there, but it also might not be a problem for our use case. TODO:--- Decide whether this really is unsafe, and if it is, what needs to--- be done to make it safe.-unsafePrettyPrint :: (Outputable.Outputable a) => a -> String-unsafePrettyPrint = Outputable.showSDocUnsafe . Outputable.ppr
src/GHC/Util/Scope.hs view
@@ -1,3 +1,4 @@+ {-# LANGUAGE ViewPatterns #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} @@ -16,7 +17,7 @@ import GHC.Util.Module import GHC.Util.RdrName-import GHC.Util.Outputable+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import Data.List.Extra import Data.Maybe
src/GHC/Util/Unify.hs view
@@ -16,14 +16,14 @@ import Util import GHC.Hs-import SrcLoc as GHC+import SrcLoc import Outputable hiding ((<>)) import RdrName import OccName import Language.Haskell.GhclibParserEx.GHC.Hs.Pat import Language.Haskell.GhclibParserEx.GHC.Hs.Expr-import GHC.Util.Outputable+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import GHC.Util.HsExpr import GHC.Util.RdrName import GHC.Util.View@@ -106,7 +106,7 @@ | Just (x, y) <- cast (x, y) = unifyExp' nm root x y | Just (x, y) <- cast (x, y) = unifyPat' nm x y | Just (x, y) <- cast (x, y) = unifyType' nm x y- | Just (x :: GHC.SrcSpan) <- cast x = Just mempty+ | Just (x :: SrcSpan) <- cast x = Just mempty | otherwise = unifyDef' nm x y unifyDef' :: Data a => NameMatch' -> a -> a -> Maybe (Subst' (LHsExpr GhcPs))
src/HSE/All.hs view
@@ -12,32 +12,27 @@ import Util import Data.Char import Data.List.Extra-import Data.Maybe import Timing import Language.Preprocessor.Cpphs-import Data.Either-import DynFlags(Language(..)) import qualified Data.Map as Map import System.IO.Extra-import Data.Functor import Fixity import Extension import FastString-import Prelude import GHC.Hs-import qualified SrcLoc as GHC+import SrcLoc import ErrUtils-import qualified Outputable-import qualified Lexer as GHC+import Outputable+import Lexer hiding (context) import GHC.LanguageExtensions.Type-import qualified ApiAnnotation as GHC-import qualified BasicTypes as GHC-import qualified DynFlags as GHC+import ApiAnnotation+import DynFlags hiding (extensions) import Bag -import GHC.Util (parsePragmasIntoDynFlags, parseFileGhcLib, parseExpGhcLib, parseDeclGhcLib, parseImportGhcLib, baseDynFlags)-import qualified Language.Haskell.GhclibParserEx.Fixity as GhclibParserEx+import Language.Haskell.GhclibParserEx.GHC.Parser+import Language.Haskell.GhclibParserEx.Fixity+import GHC.Util -- | What C pre processor should be used. data CppFlags@@ -79,19 +74,19 @@ -- | A parse error. data ParseError = ParseError- { parseErrorLocation :: GHC.SrcSpan -- ^ Location of the error.+ { parseErrorLocation :: SrcSpan -- ^ Location of the error. , parseErrorMessage :: String -- ^ Message about the cause of the error. , parseErrorContents :: String -- ^ Snippet of several lines (typically 5) including a @>@ character pointing at the faulty line. } -- | Result of 'parseModuleEx', representing a parsed module. data ModuleEx = ModuleEx {- ghcModule :: GHC.Located (HsModule GhcPs)- , ghcAnnotations :: GHC.ApiAnns+ ghcModule :: Located (HsModule GhcPs)+ , ghcAnnotations :: ApiAnns } -- | Extract a list of all of a parsed module's comments.-ghcComments :: ModuleEx -> [GHC.Located GHC.AnnotationComment]+ghcComments :: ModuleEx -> [Located AnnotationComment] ghcComments m = concat (Map.elems $ snd (ghcAnnotations m)) @@ -99,11 +94,11 @@ ghcFailOpParseModuleEx :: String -> FilePath -> String- -> (GHC.SrcSpan, ErrUtils.MsgDoc)+ -> (SrcSpan, ErrUtils.MsgDoc) -> IO (Either ParseError ModuleEx) ghcFailOpParseModuleEx ppstr file str (loc, err) = do let pe = case loc of- GHC.RealSrcSpan r -> context (GHC.srcSpanStartLine r) ppstr+ RealSrcSpan r -> context (srcSpanStartLine r) ppstr _ -> "" msg = Outputable.showSDoc baseDynFlags err pure $ Left $ ParseError loc msg pe@@ -113,35 +108,35 @@ ghcExtensionsFromParseFlags ParseFlags{extensions=exts}= (exts, []) -- GHC fixities given HSE parse flags.-ghcFixitiesFromParseFlags :: ParseFlags -> [(String, GHC.Fixity)]+ghcFixitiesFromParseFlags :: ParseFlags -> [(String, Fixity)] ghcFixitiesFromParseFlags = map toFixity . fixities -- These next two functions get called frorm 'Config/Yaml.hs' for user -- defined hint rules. -parseModeToFlags :: ParseFlags -> GHC.DynFlags+parseModeToFlags :: ParseFlags -> DynFlags parseModeToFlags parseMode =- flip GHC.lang_set (baseLanguage parseMode) $ foldl' GHC.xopt_unset (foldl' GHC.xopt_set baseDynFlags enable) disable+ flip lang_set (baseLanguage parseMode) $ foldl' xopt_unset (foldl' xopt_set baseDynFlags enable) disable where (enable, disable) = ghcExtensionsFromParseFlags parseMode -parseExpGhcWithMode :: ParseFlags -> String -> GHC.ParseResult (LHsExpr GhcPs)+parseExpGhcWithMode :: ParseFlags -> String -> ParseResult (LHsExpr GhcPs) parseExpGhcWithMode parseMode s = let fixities = ghcFixitiesFromParseFlags parseMode- in case parseExpGhcLib s $ parseModeToFlags parseMode of- GHC.POk pst a -> GHC.POk pst (GhclibParserEx.applyFixities fixities a)- f@GHC.PFailed{} -> f+ in case parseExpression s $ parseModeToFlags parseMode of+ POk pst a -> POk pst $ applyFixities fixities a+ f@PFailed{} -> f -parseImportDeclGhcWithMode :: ParseFlags -> String -> GHC.ParseResult (LImportDecl GhcPs)+parseImportDeclGhcWithMode :: ParseFlags -> String -> ParseResult (LImportDecl GhcPs) parseImportDeclGhcWithMode parseMode s =- parseImportGhcLib s $ parseModeToFlags parseMode+ parseImport s $ parseModeToFlags parseMode -parseDeclGhcWithMode :: ParseFlags -> String -> GHC.ParseResult (LHsDecl GhcPs)+parseDeclGhcWithMode :: ParseFlags -> String -> ParseResult (LHsDecl GhcPs) parseDeclGhcWithMode parseMode s = let fixities = ghcFixitiesFromParseFlags parseMode- in case parseDeclGhcLib s $ parseModeToFlags parseMode of- GHC.POk pst a -> GHC.POk pst (GhclibParserEx.applyFixities fixities a)- f@GHC.PFailed{} -> f+ in case parseDeclaration s $ parseModeToFlags parseMode of+ POk pst a -> POk pst $ applyFixities fixities a+ f@PFailed{} -> f -- | Parse a Haskell module. Applies the C pre processor, and uses -- best-guess fixity resolution if there are ambiguities. The@@ -161,31 +156,34 @@ dynFlags <- parsePragmasIntoDynFlags baseDynFlags enableDisableExts file ppstr case dynFlags of Right ghcFlags -> do- ghcFlags <- pure $ GHC.lang_set ghcFlags $ baseLanguage flags- case parseFileGhcLib file ppstr ghcFlags of- GHC.POk pst a ->- let anns =- ( Map.fromListWith (++) $ GHC.annotations pst- , Map.fromList ((GHC.noSrcSpan, GHC.comment_q pst) : GHC.annotations_comments pst)- ) in- let a' = GhclibParserEx.applyFixities fixities a in- pure $ Right (ModuleEx a' anns)- -- Parse error if GHC parsing fails (see- -- https://github.com/ndmitchell/hlint/issues/645).- GHC.PFailed s -> do- let (_, errs) = GHC.getMessages s ghcFlags- errMsg = head (bagToList errs)- loc = errMsgSpan errMsg- doc = formatErrDoc ghcFlags (errMsgDoc errMsg)- ghcFailOpParseModuleEx ppstr file str (loc, doc)+ ghcFlags <- pure $ lang_set ghcFlags $ baseLanguage flags+ case fileToModule file ppstr ghcFlags of+ POk s a -> do+ let errs = bagToList . snd $ getMessages s ghcFlags+ if not $ null errs then+ handleParseFailure ghcFlags ppstr file str errs+ else do+ let anns =+ ( Map.fromListWith (++) $ annotations s+ , Map.fromList ((noSrcSpan, comment_q s) : annotations_comments s)+ )+ pure $ Right (ModuleEx (applyFixities fixities a) anns)+ PFailed s ->+ handleParseFailure ghcFlags ppstr file str $ bagToList . snd $ getMessages s ghcFlags Left msg -> do -- Parsing GHC flags from dynamic pragmas in the source -- has failed. When this happens, it's reported by -- exception. It's impossible or at least fiddly getting a -- location so we skip that for now. Synthesize a parse -- error.- let loc = GHC.mkSrcLoc (mkFastString file) (1 :: Int) (1 :: Int)- pure $ Left (ParseError (GHC.mkSrcSpan loc loc) msg ppstr)+ let loc = mkSrcLoc (mkFastString file) (1 :: Int) (1 :: Int)+ pure $ Left (ParseError (mkSrcSpan loc loc) msg ppstr)+ where+ handleParseFailure ghcFlags ppstr file str errs =+ let errMsg = head errs+ loc = errMsgSpan errMsg+ doc = formatErrDoc ghcFlags (errMsgDoc errMsg)+ in ghcFailOpParseModuleEx ppstr file str (loc, doc) -- | Given a line number, and some source code, put bird ticks around the appropriate bit.
src/Hint/Bracket.hs view
@@ -89,6 +89,7 @@ special = foo $ f{x=1} special = foo $ Rec{x=1} special = foo (f{x=1})+loadCradleOnlyonce = skipManyTill anyMessage (message @PublishDiagnosticsNotification) </TEST> -} @@ -106,6 +107,7 @@ import SrcLoc import GHC.Util import Language.Haskell.GhclibParserEx.GHC.Hs.Expr+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable bracketHint :: DeclHint' bracketHint _ _ x =
src/Hint/Duplicate.hs view
@@ -37,6 +37,7 @@ import Bag import GHC.Util import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable duplicateHint :: CrossHint duplicateHint ms =
src/Hint/Extensions.hs view
@@ -231,6 +231,7 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.Types import Language.Haskell.GhclibParserEx.GHC.Hs.Decls import Language.Haskell.GhclibParserEx.GHC.Driver.Session+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable extensionsHint :: ModuHint extensionsHint _ x =
src/Hint/Import.hs view
@@ -55,7 +55,9 @@ import Module import GHC.Hs import SrcLoc-import GHC.Util++import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable+ importHint :: ModuHint importHint _ ModuleEx {ghcModule=L _ HsModule{hsmodImports=ms}} =
src/Hint/Lambda.hs view
@@ -108,11 +108,11 @@ import GHC.Util.Brackets (isAtom') import GHC.Util.FreeVars (free', allVars', freeVars', pvars', vars', varss') import GHC.Util.HsExpr (allowLeftSection, allowRightSection, niceLambdaR', lambda)-import GHC.Util.Outputable import GHC.Util.RdrName (rdrNameStr') import GHC.Util.View import GHC.Hs import Language.Haskell.GhclibParserEx.GHC.Hs.Expr (isTypeApp, isOpApp, isLambda, isQuasiQuote, isVar, isDol, strToVar)+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import OccName import RdrName import SrcLoc
src/Hint/List.hs view
@@ -63,6 +63,7 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.Types import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable listHint :: DeclHint' listHint _ _ = listDecl
src/Hint/ListRec.hs view
@@ -56,6 +56,7 @@ import Language.Haskell.GhclibParserEx.GHC.Hs.Pat import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable listRecHint :: DeclHint' listRecHint _ _ = concatMap f . universe
src/Hint/Match.hs view
@@ -61,6 +61,7 @@ import GHC.Util import Language.Haskell.GhclibParserEx.GHC.Hs.Expr import Language.Haskell.GhclibParserEx.GHC.Hs.ExtendInstances+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable readMatch' :: [HintRule] -> Scope -> ModuleEx -> LHsDecl GhcPs -> [Idea] readMatch' settings = findIdeas' (concatMap readRule' settings)
src/Hint/Monad.hs view
@@ -67,6 +67,7 @@ import Bag import Language.Haskell.GhclibParserEx.GHC.Hs.Pat import Language.Haskell.GhclibParserEx.GHC.Hs.Expr+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import GHC.Util import Data.Tuple.Extra
src/Hint/Naming.hs view
@@ -59,6 +59,7 @@ import SrcLoc import Language.Haskell.GhclibParserEx.GHC.Hs.Decls+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable import GHC.Util namingHint :: DeclHint'
src/Hint/Pattern.hs view
@@ -77,6 +77,7 @@ import GHC.Util import Language.Haskell.GhclibParserEx.GHC.Hs.Pat import Language.Haskell.GhclibParserEx.GHC.Hs.Expr+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable patternHint :: DeclHint' patternHint _scope modu x =
src/Hint/Smell.hs view
@@ -91,7 +91,7 @@ import Outputable import Bag import SrcLoc-import GHC.Util+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable smellModuleHint :: [Setting] -> ModuHint smellModuleHint settings scope m =
src/Hint/Unsafe.hs view
@@ -30,7 +30,7 @@ import BasicTypes import SrcLoc import Language.Haskell.GhclibParserEx.GHC.Hs.Expr-import GHC.Util+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable -- The conditions on which to fire this hint are subtle. We are -- interested exclusively in application constants involving
src/Idea.hs view
@@ -16,17 +16,19 @@ import Refact.Types hiding (SrcSpan) import qualified Refact.Types as R import Prelude-import qualified SrcLoc as GHC-import qualified Outputable-import qualified GHC.Util as GHC+import SrcLoc+import Outputable+import GHC.Util +import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable+ -- | An idea suggest by a 'Hint'. data Idea = Idea {ideaModule :: [String] -- ^ The modules the idea is for, usually a singleton. ,ideaDecl :: [String] -- ^ The declarations the idea is for, usually a singleton, typically the function name, but may be a type name. ,ideaSeverity :: Severity -- ^ The severity of the idea, e.g. 'Warning'. ,ideaHint :: String -- ^ The name of the hint that generated the idea, e.g. @\"Use reverse\"@.- ,ideaSpan :: GHC.SrcSpan -- ^ The source code the idea relates to.+ ,ideaSpan :: SrcSpan -- ^ The source code the idea relates to. ,ideaFrom :: String -- ^ The contents of the source code the idea relates to. ,ideaTo :: Maybe String -- ^ The suggested replacement, or 'Nothing' for no replacement (e.g. on parse errors). ,ideaNote :: [Note] -- ^ Notes about the effect of applying the replacement.@@ -38,7 +40,7 @@ -- 1) Aeson doesn't esape unicode characters, and I want to (allows me to ignore encoding) -- 2) I want to control the format so it's slightly human readable as well showIdeaJson :: Idea -> String-showIdeaJson idea@Idea{ideaSpan=srcSpan@GHC.SrcSpan{..}, ..} = dict+showIdeaJson idea@Idea{ideaSpan=srcSpan@SrcSpan{..}, ..} = dict [("module", list $ map str ideaModule) ,("decl", list $ map str ideaDecl) ,("severity", str $ show ideaSeverity)@@ -70,7 +72,7 @@ showEx :: (String -> String) -> Idea -> String showEx tt Idea{..} = unlines $- [GHC.showSrcSpan' ideaSpan ++ ": " ++ (if ideaHint == "" then "" else show ideaSeverity ++ ": " ++ ideaHint)] +++ [showSrcSpan' ideaSpan ++ ": " ++ (if ideaHint == "" then "" else show ideaSeverity ++ ": " ++ ideaHint)] ++ f "Found" (Just ideaFrom) ++ f "Perhaps" ideaTo ++ ["Note: " ++ n | let n = showNotes ideaNote, n /= ""] where@@ -80,53 +82,53 @@ where xs = lines $ tt x -rawIdea :: Severity -> String -> GHC.SrcSpan -> String -> Maybe String -> [Note]-> [Refactoring R.SrcSpan] -> Idea+rawIdea :: Severity -> String -> SrcSpan -> String -> Maybe String -> [Note]-> [Refactoring R.SrcSpan] -> Idea rawIdea = Idea [] [] -rawIdea' :: Severity -> String -> GHC.SrcSpan -> String -> Maybe String -> [Note]-> [Refactoring R.SrcSpan] -> Idea+rawIdea' :: Severity -> String -> SrcSpan -> String -> Maybe String -> [Note]-> [Refactoring R.SrcSpan] -> Idea rawIdea' = Idea [] [] -rawIdeaN :: Severity -> String -> GHC.SrcSpan -> String -> Maybe String -> [Note] -> Idea+rawIdeaN :: Severity -> String -> SrcSpan -> String -> Maybe String -> [Note] -> Idea rawIdeaN a b c d e f = Idea [] [] a b c d e f [] -rawIdeaN' :: Severity -> String -> GHC.SrcSpan -> String -> Maybe String -> [Note] -> Idea+rawIdeaN' :: Severity -> String -> SrcSpan -> String -> Maybe String -> [Note] -> Idea rawIdeaN' a b span d e f = Idea [] [] a b span d e f [] -idea' :: (GHC.HasSrcSpan a, Outputable.Outputable a, GHC.HasSrcSpan b, Outputable.Outputable b) =>+idea' :: (HasSrcSpan a, Outputable.Outputable a, HasSrcSpan b, Outputable.Outputable b) => Severity -> String -> a -> b -> [Refactoring R.SrcSpan] -> Idea idea' severity hint from to =- rawIdea severity hint (GHC.getLoc from) (GHC.unsafePrettyPrint from) (Just $ GHC.unsafePrettyPrint to) []+ rawIdea severity hint (getLoc from) (unsafePrettyPrint from) (Just $ unsafePrettyPrint to) [] -- Construct an Idea that suggests "Perhaps you should remove it."-ideaRemove :: Severity -> String -> GHC.SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea+ideaRemove :: Severity -> String -> SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea ideaRemove severity hint span from = rawIdea severity hint span from (Just "") [] -suggest' :: (GHC.HasSrcSpan a, Outputable.Outputable a, GHC.HasSrcSpan b, Outputable.Outputable b) =>+suggest' :: (HasSrcSpan a, Outputable.Outputable a, HasSrcSpan b, Outputable.Outputable b) => String -> a -> b -> [Refactoring R.SrcSpan] -> Idea suggest' = idea' Suggestion -suggestRemove :: String -> GHC.SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea+suggestRemove :: String -> SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea suggestRemove = ideaRemove Suggestion -warn' :: (GHC.HasSrcSpan a, Outputable.Outputable a, GHC.HasSrcSpan b, Outputable.Outputable b) =>+warn' :: (HasSrcSpan a, Outputable.Outputable a, HasSrcSpan b, Outputable.Outputable b) => String -> a -> b -> [Refactoring R.SrcSpan] -> Idea warn' = idea' Warning -warnRemove :: String -> GHC.SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea+warnRemove :: String -> SrcSpan -> String -> [Refactoring R.SrcSpan] -> Idea warnRemove = ideaRemove Warning -ignoreNoSuggestion' :: (GHC.HasSrcSpan a, Outputable.Outputable a)+ignoreNoSuggestion' :: (HasSrcSpan a, Outputable.Outputable a) => String -> a -> Idea-ignoreNoSuggestion' hint x = rawIdeaN Ignore hint (GHC.getLoc x) (GHC.unsafePrettyPrint x) Nothing []+ignoreNoSuggestion' hint x = rawIdeaN Ignore hint (getLoc x) (unsafePrettyPrint x) Nothing [] -ignore' :: (GHC.HasSrcSpan a, Outputable.Outputable a) =>+ignore' :: (HasSrcSpan a, Outputable.Outputable a) => String -> a -> a -> [Refactoring R.SrcSpan] -> Idea ignore' = idea' Ignore -ideaN' :: (GHC.HasSrcSpan a, Outputable.Outputable a) =>+ideaN' :: (HasSrcSpan a, Outputable.Outputable a) => Severity -> String -> a -> a -> Idea ideaN' severity hint from to = idea' severity hint from to [] -suggestN' :: (GHC.HasSrcSpan a, Outputable.Outputable a) =>+suggestN' :: (HasSrcSpan a, Outputable.Outputable a) => String -> a -> a -> Idea suggestN' = ideaN' Suggestion
src/Test/All.hs view
@@ -25,7 +25,7 @@ import Test.Annotations import Test.Translate import System.IO.Extra-import GHC.Util.Outputable+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable test :: Cmd -> ([String] -> IO ()) -> FilePath -> [FilePath] -> IO Int
src/Test/Annotations.hs view
@@ -27,17 +27,16 @@ import Test.Util import Prelude import Config.Yaml-import GHC.Util.Outputable import FastString -import qualified GHC.Util as GHC-import qualified SrcLoc as GHC-+import GHC.Util+import SrcLoc+import Language.Haskell.GhclibParserEx.GHC.Utils.Outputable -- Input, Output -- Output = Nothing, should not match -- Output = Just xs, should match xs-data TestCase = TestCase GHC.SrcLoc Refactor String (Maybe String) [Setting] deriving (Show)+data TestCase = TestCase SrcLoc Refactor String (Maybe String) [Setting] deriving (Show) data Refactor = TestRefactor | SkipRefactor deriving (Eq, Show) @@ -74,7 +73,7 @@ ,"SRC: " ++ unsafePrettyPrint loc ,"INPUT: " ++ inp ,"OUTPUT: " ++ show i]- | i@Idea{..} <- fromRight [] ideas, let GHC.SrcLoc{..} = GHC.srcSpanStart ideaSpan, srcFilename == "" || srcLine == 0 || srcColumn == 0]+ | i@Idea{..} <- fromRight [] ideas, let SrcLoc{..} = srcSpanStart ideaSpan, srcFilename == "" || srcLine == 0 || srcColumn == 0] -- TODO: shouldn't these checks be == -1 instead? -- Skip refactoring test if the hlint test failed, or if the@@ -136,7 +135,7 @@ parseTest :: Refactor -> String -> Int -> String -> [Setting] -> TestCase-parseTest refact file i x = uncurry (TestCase (GHC.mkSrcLoc (mkFastString file) i 0) refact) $ f x+parseTest refact file i x = uncurry (TestCase (mkSrcLoc (mkFastString file) i 0) refact) $ f x where f x | Just x <- stripPrefix "<COMMENT>" x = first ("--"++) $ f x f (' ':'-':'-':xs) | null xs || " " `isPrefixOf` xs = ("", Just $ trimStart xs)