on master help sign in
Fix HLint warnings
commite91ced82c4087454ee004f8ef948fe1a32a37a29 authorYuriy Syrovetskiy <cblp@cblp.su> dateThu 7 Nov 2019, 17:48 (7 years ago) parent40ec6b0
23 files changed+55−73
src/Ormolu.hs+1−3 src/Ormolu/Config.hs−4 src/Ormolu/Diff.hs+1−3 src/Ormolu/Exception.hs+12−10 src/Ormolu/Parser.hs−1 src/Ormolu/Parser/CommentStream.hs−2 src/Ormolu/Parser/Pragma.hs+1−1 src/Ormolu/Printer.hs−2 src/Ormolu/Printer/Combinators.hs−1 src/Ormolu/Printer/Comments.hs+4−6 src/Ormolu/Printer/Internal.hs−1 src/Ormolu/Printer/Meat/Declaration.hs+1−1 src/Ormolu/Printer/Meat/Declaration/Data.hs+2−3 src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs−1 src/Ormolu/Printer/Meat/Declaration/Rule.hs−1 src/Ormolu/Printer/Meat/Declaration/TypeFamily.hs+1−2 src/Ormolu/Printer/Meat/Declaration/Value.hs+5−6 src/Ormolu/Printer/Meat/Declaration/Warning.hs+6−4 src/Ormolu/Printer/Meat/ImportExport.hs+1−1 src/Ormolu/Printer/Meat/Module.hs−1 src/Ormolu/Printer/Meat/Type.hs+10−9 src/Ormolu/Printer/Operators.hs+9−9 tests/Ormolu/Parser/PragmaSpec.hs+1−1
src/Ormolu.hs+1−3
@@ -1,5 +1,4 @@
11{-# LANGUAGE BangPatterns #-}
2−{-# LANGUAGE RecordWildCards #-}
32
43-- | A formatter for Haskell source code.
54module Ormolu
@@ -29,7 +28,6 @@ import Ormolu.Parser.Result
2928import Ormolu.Printer
3029import Ormolu.Utils (showOutputable)
3130import qualified SrcLoc as GHC
32−import System.IO (hGetContents, stdin)
3331
3432-- | Format a 'String', return formatted version as 'Text'.
3533--
@@ -115,7 +113,7 @@ ormoluStdin ::
115113 -- | Resulting rendition
116114 m Text
117115ormoluStdin cfg =
118− liftIO (hGetContents stdin) >>= ormolu cfg "<stdin>"
116+ liftIO getContents >>= ormolu cfg "<stdin>"
119117
120118----------------------------------------------------------------------------
121119-- Helpers
src/Ormolu/Config.hs−4
@@ -1,7 +1,3 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE RecordWildCards #-}
4−
51-- | Configuration options used by the tool.
62module Ormolu.Config
73 ( Config (..),
src/Ormolu/Diff.hs+1−3
@@ -1,6 +1,4 @@
1−{-# LANGUAGE DeriveDataTypeable #-}
21{-# LANGUAGE RankNTypes #-}
3−{-# LANGUAGE RecordWildCards #-}
42
53-- | Diffing GHC ASTs modulo span positions.
64module Ormolu.Diff
@@ -107,7 +105,7 @@ matchIgnoringSrcSpans = genericQuery
107105 appendSpan :: SrcSpan -> Diff -> Diff
108106 appendSpan s (Different ss) | fresh && helpful = Different (s : ss)
109107 where
110− fresh = not $ any (flip isSubspanOf s) ss
108+ fresh = not $ any (`isSubspanOf` s) ss
111109 helpful = isGoodSrcSpan s
112110 appendSpan _ d = d
113111
src/Ormolu/Exception.hs+12−10
@@ -49,10 +49,12 @@ instance Exception OrmoluException where
4949 unlines $
5050 [ "AST of input and AST of formatted code differ."
5151 ]
52− ++ ( fmap withIndent $ case fmap (\s -> "at " ++ showOutputable s) ss of
53− [] -> ["in " ++ path]
54− xs -> xs
55− )
52+ ++ fmap
53+ withIndent
54+ ( case fmap (\s -> "at " ++ showOutputable s) ss of
55+ [] -> ["in " ++ path]
56+ xs -> xs
57+ )
5658 ++ ["Please, consider reporting the bug."]
5759 OrmoluNonIdempotentOutput loc left right ->
5860 showParsingErr
@@ -80,12 +82,12 @@ withPrettyOrmoluExceptions m = m `catch` h
8082 exitWith . ExitFailure $
8183 case e of
8284 -- Error code 1 is for `error` or `notImplemented`
83− OrmoluCppEnabled _ -> 2
84− OrmoluParsingFailed _ _ -> 3
85− OrmoluOutputParsingFailed _ _ -> 4
86− OrmoluASTDiffers _ _ -> 5
87− OrmoluNonIdempotentOutput _ _ _ -> 6
88− OrmoluUnrecognizedOpts _ -> 7
85+ OrmoluCppEnabled {} -> 2
86+ OrmoluParsingFailed {} -> 3
87+ OrmoluOutputParsingFailed {} -> 4
88+ OrmoluASTDiffers {} -> 5
89+ OrmoluNonIdempotentOutput {} -> 6
90+ OrmoluUnrecognizedOpts {} -> 7
8991
9092----------------------------------------------------------------------------
9193-- Helpers
src/Ormolu/Parser.hs−1
@@ -1,6 +1,5 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE RecordWildCards #-}
3−{-# LANGUAGE StandaloneDeriving #-}
43{-# OPTIONS_GHC -fno-warn-orphans #-}
54
65-- | Parser for Haskell source code.
src/Ormolu/Parser/CommentStream.hs−2
@@ -1,8 +1,6 @@
1−{-# LANGUAGE BangPatterns #-}
21{-# LANGUAGE DeriveDataTypeable #-}
32{-# LANGUAGE GeneralizedNewtypeDeriving #-}
43{-# LANGUAGE LambdaCase #-}
5−{-# LANGUAGE TupleSections #-}
64
75-- | Functions for working with comment stream.
86module Ormolu.Parser.CommentStream
src/Ormolu/Parser/Pragma.hs+1−1
@@ -54,7 +54,7 @@ parseExtensions :: String -> Maybe [String]
5454parseExtensions str = tokenize str >>= go
5555 where
5656 go = \case
57− (L.ITconid ext : []) -> return [unpackFS ext]
57+ [L.ITconid ext] -> return [unpackFS ext]
5858 (L.ITconid ext : L.ITcomma : xs) -> (unpackFS ext :) <$> go xs
5959 _ -> Nothing
6060
src/Ormolu/Printer.hs−2
@@ -1,5 +1,3 @@
1−{-# LANGUAGE LambdaCase #-}
2−{-# LANGUAGE OverloadedStrings #-}
31{-# LANGUAGE RecordWildCards #-}
42
53-- | Pretty-printer for Haskell AST.
src/Ormolu/Printer/Combinators.hs−1
@@ -2,7 +2,6 @@
22{-# LANGUAGE GADTs #-}
33{-# LANGUAGE LambdaCase #-}
44{-# LANGUAGE OverloadedStrings #-}
5−{-# LANGUAGE RecordWildCards #-}
65
76-- | Printing combinators. The definitions here are presented in such an
87-- order so you can just go through the Haddocks and by the end of the file
src/Ormolu/Printer/Comments.hs+4−6
@@ -1,4 +1,3 @@
1−{-# LANGUAGE LambdaCase #-}
21{-# LANGUAGE OverloadedStrings #-}
32
43-- | Helpers for formatting of comments. This is low-level code, use
@@ -244,11 +243,10 @@ commentFollowsElt ref mnSpn meSpn mlastSpn (L l comment) =
244243 Nothing -> True
245244 Just espn ->
246245 let startColumn = srcLocCol . realSrcSpanStart
247− in if startColumn espn > startColumn ref
248− then True
249− else
250− abs (startColumn espn - startColumn l)
251− >= abs (startColumn ref - startColumn l)
246+ in startColumn espn > startColumn ref
247+ || ( abs (startColumn espn - startColumn l)
248+ >= abs (startColumn ref - startColumn l)
249+ )
252250 continuation =
253251 case mlastSpn of
254252 Nothing -> False
src/Ormolu/Printer/Internal.hs−1
@@ -1,5 +1,4 @@
11{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2−{-# LANGUAGE LambdaCase #-}
32{-# LANGUAGE OverloadedStrings #-}
43{-# LANGUAGE RankNTypes #-}
54
src/Ormolu/Printer/Meat/Declaration.hs+1−1
@@ -257,6 +257,6 @@ patBindNames (SigPat _ p _) = patBindNames p
257257patBindNames (NPat NoExt _ _ _) = []
258258patBindNames (NPlusKPat NoExt (L _ n) _ _ _ _) = [n]
259259patBindNames (ConPatIn _ d) = concatMap (patBindNames . unLoc) (hsConPatArgs d)
260−patBindNames (ConPatOut _ _ _ _ _ _ _) = notImplemented "ConPatOut" -- created by renamer
260+patBindNames ConPatOut {} = notImplemented "ConPatOut" -- created by renamer
261261patBindNames (CoPat NoExt _ p _) = patBindNames p
262262patBindNames (XPat p) = patBindNames (unLoc p)
src/Ormolu/Printer/Meat/Declaration/Data.hs+2−3
@@ -9,8 +9,7 @@ module Ormolu.Printer.Meat.Declaration.Data
99where
1010
1111import Control.Monad
12−import Data.Maybe (isJust)
13−import Data.Maybe (maybeToList)
12+import Data.Maybe (isJust, maybeToList)
1413import GHC
1514import Ormolu.Printer.Combinators
1615import Ormolu.Printer.Meat.Common
@@ -73,7 +72,7 @@ p_dataDecl style name tpats fixity HsDataDefn {..} = do
7372 (newline >> txt "|" >> space)
7473 sep s (sitcc . located' p_conDecl) dd_cons
7574 unless (null $ unLoc dd_derivs) breakpoint
76− inci . located dd_derivs $ \xs -> do
75+ inci . located dd_derivs $ \xs ->
7776 sep newline (located' p_hsDerivingClause) xs
7877p_dataDecl _ _ _ _ (XHsDataDefn NoExt) = notImplemented "XHsDataDefn"
7978
src/Ormolu/Printer/Meat/Declaration/RoleAnnotation.hs−1
@@ -1,6 +1,5 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE RecordWildCards #-}
43{-# LANGUAGE TypeFamilies #-}
54
65-- | Rendering of Role annotation declarations.
src/Ormolu/Printer/Meat/Declaration/Rule.hs−1
@@ -1,6 +1,5 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
3−{-# LANGUAGE RecordWildCards #-}
43
54module Ormolu.Printer.Meat.Declaration.Rule
65 ( p_ruleDecls,
src/Ormolu/Printer/Meat/Declaration/TypeFamily.hs+1−2
@@ -37,8 +37,7 @@ p_famDecl style FamilyDecl {fdTyVars = HsQTvs {..}, ..} = do
3737 (p_rdrName fdLName)
3838 (located' p_hsTyVarBndr <$> hsq_explicit)
3939 let rsig = p_familyResultSigL fdResultSig
40− unless (isNothing rsig && isNothing fdInjectivityAnn) $
41− space
40+ unless (isNothing rsig && isNothing fdInjectivityAnn) space
4241 inci $ do
4342 sequence_ rsig
4443 when (isJust rsig && isJust fdInjectivityAnn) breakpoint
src/Ormolu/Printer/Meat/Declaration/Value.hs+5−6
@@ -32,8 +32,7 @@ import Ormolu.Printer.Meat.Declaration.Signature
3232import Ormolu.Printer.Meat.Type
3333import Ormolu.Printer.Operators
3434import Ormolu.Utils
35−import RdrName (RdrName (..))
36−import RdrName (rdrNameOcc)
35+import RdrName (RdrName (..), rdrNameOcc)
3736import SrcLoc (combineSrcSpans, isOneLineSpan)
3837
3938-- | Style of a group of equations.
@@ -456,7 +455,7 @@ p_hsLocalBinds = \case
456455 -- Assigns 'False' to the last element, 'True' to the rest.
457456 markInit :: [a] -> [(Bool, a)]
458457 markInit [] = []
459− markInit (x : []) = [(False, x)]
458+ markInit [x] = [(False, x)]
460459 markInit (x : xs) = (True, x) : markInit xs
461460 -- NOTE When in a single-line layout, there is a chance that the inner
462461 -- elements will also contain semicolons and they will confuse the
@@ -838,7 +837,7 @@ p_case ::
838837 -- | Expression
839838 LHsExpr GhcPs ->
840839 -- | Match group
841− (MatchGroup GhcPs (Located body)) ->
840+ MatchGroup GhcPs (Located body) ->
842841 R ()
843842p_case placer render e mgroup = do
844843 txt "case"
@@ -1164,7 +1163,7 @@ blockPlacement ::
11641163 (body -> Placement) ->
11651164 [LGRHS GhcPs (Located body)] ->
11661165 Placement
1167−blockPlacement placer [(L _ (GRHS NoExt _ (L _ x)))] = placer x
1166+blockPlacement placer [L _ (GRHS NoExt _ (L _ x))] = placer x
11681167blockPlacement _ _ = Normal
11691168
11701169-- | Check if given command has a hanging form.
@@ -1257,7 +1256,7 @@ p_exprOpTree isDollarSpecial s (OpBranch x op y) = do
12571256 Hanging -> useBraces
12581257 Normal -> dontUseBraces
12591258 gotDollar = case getOpName (unLoc op) of
1260− Just rname -> mkVarOcc "$" == (rdrNameOcc rname)
1259+ Just rname -> mkVarOcc "$" == rdrNameOcc rname
12611260 _ -> False
12621261 lhs =
12631262 switchLayout [opTreeLoc x] $
src/Ormolu/Printer/Meat/Declaration/Warning.hs+6−4
@@ -28,14 +28,16 @@ p_warnDecl XWarnDecl {} = notImplemented "XWarnDecl"
2828p_moduleWarning :: WarningTxt -> R ()
2929p_moduleWarning wtxt = do
3030 let (pragmaText, lits) = warningText wtxt
31− switchLayout (getLoc <$> lits) $ do
32− inci $ pragma pragmaText (inci $ p_lits lits)
31+ switchLayout (getLoc <$> lits)
32+ $ inci
33+ $ pragma pragmaText (inci $ p_lits lits)
3334
3435p_topLevelWarning :: [Located RdrName] -> WarningTxt -> R ()
3536p_topLevelWarning fnames wtxt = do
3637 let (pragmaText, lits) = warningText wtxt
37− switchLayout (fmap getLoc fnames ++ fmap getLoc lits) $ do
38− pragma pragmaText . inci $ do
38+ switchLayout (fmap getLoc fnames ++ fmap getLoc lits)
39+ $ pragma pragmaText . inci
40+ $ do
3941 sitcc $ sep (comma >> breakpoint) p_rdrName fnames
4042 breakpoint
4143 p_lits lits
src/Ormolu/Printer/Meat/ImportExport.hs+1−1
@@ -56,7 +56,7 @@ p_hsmodImport ImportDecl {..} = do
5656 when hiding (txt "hiding")
5757 case ideclHiding of
5858 Nothing -> return ()
59− Just (_, (L _ xs)) -> do
59+ Just (_, L _ xs) -> do
6060 breakpoint
6161 parens N . sitcc $ do
6262 layout <- getLayout
src/Ormolu/Printer/Meat/Module.hs−1
@@ -1,4 +1,3 @@
1−{-# LANGUAGE LambdaCase #-}
21{-# LANGUAGE OverloadedStrings #-}
32{-# LANGUAGE RecordWildCards #-}
43
src/Ormolu/Printer/Meat/Type.hs+10−9
@@ -84,9 +84,10 @@ p_hsType' multilineArgs = \case
8484 HsSumTy NoExt xs ->
8585 parensHash N . sitcc $
8686 sep (txt "|" >> breakpoint) (sitcc . located' p_hsType) xs
87− HsOpTy NoExt x op y -> sitcc $ do
88− let opTree = OpBranch (tyOpTree x) op (tyOpTree y)
89− in p_tyOpTree (reassociateOpTree Just opTree)
87+ HsOpTy NoExt x op y ->
88+ sitcc $
89+ let opTree = OpBranch (tyOpTree x) op (tyOpTree y)
90+ in p_tyOpTree (reassociateOpTree Just opTree)
9091 HsParTy NoExt t ->
9192 parens N (located t p_hsType)
9293 HsIParamTy NoExt n t -> sitcc $ do
@@ -126,14 +127,14 @@ p_hsType' multilineArgs = \case
126127 -- If both this list itself and the first element is promoted,
127128 -- we need to put a space in between or it fails to parse.
128129 case (p, xs) of
129− (IsPromoted, ((L _ t) : _)) | isPromoted t -> space
130+ (IsPromoted, L _ t : _) | isPromoted t -> space
130131 _ -> return ()
131132 sitcc $ sep (comma >> breakpoint) (sitcc . located' p_hsType) xs
132133 HsExplicitTupleTy NoExt xs -> do
133134 txt "'"
134135 parens N $ do
135136 case xs of
136− ((L _ t) : _) | isPromoted t -> space
137+ L _ t : _ | isPromoted t -> space
137138 _ -> return ()
138139 sep (comma >> breakpoint) (located' p_hsType) xs
139140 HsTyLit NoExt t ->
@@ -145,8 +146,8 @@ p_hsType' multilineArgs = \case
145146 where
146147 isPromoted = \case
147148 HsTyVar _ IsPromoted _ -> True
148− HsExplicitListTy _ _ _ -> True
149− HsExplicitTupleTy _ _ -> True
149+ HsExplicitListTy {} -> True
150+ HsExplicitTupleTy {} -> True
150151 _ -> False
151152 interArgBreak =
152153 if multilineArgs
@@ -158,7 +159,7 @@ p_hsType' multilineArgs = \case
158159-- attached to it.
159160hasDocStrings :: HsType GhcPs -> Bool
160161hasDocStrings = \case
161− HsDocTy _ _ _ -> True
162+ HsDocTy {} -> True
162163 HsFunTy _ (L _ x) (L _ y) -> hasDocStrings x || hasDocStrings y
163164 _ -> False
164165
@@ -220,7 +221,7 @@ tyOpTree n = OpNode n
220221p_tyOpTree :: OpTree (LHsType GhcPs) (Located RdrName) -> R ()
221222p_tyOpTree (OpNode n) = located n p_hsType
222223p_tyOpTree (OpBranch l op r) = do
223− switchLayout [opTreeLoc l] $ do
224+ switchLayout [opTreeLoc l] $
224225 p_tyOpTree l
225226 breakpoint
226227 inci . switchLayout [opTreeLoc r] $ do
src/Ormolu/Printer/Operators.hs+9−9
@@ -129,17 +129,17 @@ buildFixityMap getOpName opTree =
129129 rb <- srcSpanStartLine <$> unSrcSpan (opTreeLoc r) -- right begin
130130 oc <- srcSpanStartCol <$> unSrcSpan (getLoc o) -- operator column
131131 opName <- getOpName (unLoc o)
132− let s =
133− if le < ob
134− then-- if the operator is in the beginning of a line, assign
132+ let s
133+ | le < ob =
134+ -- if the operator is in the beginning of a line, assign
135135 -- a score relative to its column within range [0, 1).
136− fromIntegral oc / fromIntegral (maxCol + 1)
137− else-- if the operator is in the end of the line, assign the
136+ fromIntegral oc / fromIntegral (maxCol + 1)
137+ | oe < rb =
138+ -- if the operator is in the end of the line, assign the
138139 -- score 1.
139−
140− if oe < rb
141− then 1
142− else 2 -- otherwise, assign a high score.
140+ 1
141+ | otherwise =
142+ 2 -- otherwise, assign a high score.
143143 return $ (opName, s) : score r
144144 avgScores :: [(RdrName, Double)] -> [(RdrName, Double)]
145145 avgScores =
tests/Ormolu/Parser/PragmaSpec.hs+1−1
@@ -4,7 +4,7 @@ import Ormolu.Parser.Pragma
44import Test.Hspec
55
66spec :: Spec
7−spec = do
7+spec =
88 describe "parsePragma" $ do
99 stdTest "{-# LANGUAGE Foo #-}" (Just (PragmaLanguage ["Foo"]))
1010 stdTest "{-# language Foo #-}" (Just (PragmaLanguage ["Foo"]))