packages feed

hlint 1.8.42 → 1.8.43

raw patch · 6 files changed

+25/−10 lines, 6 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

data/Default.hs view
@@ -103,7 +103,7 @@ warn  = length x == 0 ==> null x where note = IncreasesLaziness warn  = x == [] ==> null x warn  "Use null" = length x /= 0 ==> not (null x) where note = IncreasesLaziness-error "Use :" = (\x -> [x]) ==> (:[])+warn  "Use :" = (\x -> [x]) ==> (:[]) error = map (uncurry f) (zip x y) ==> zipWith f x y warn  = map f (zip x y) ==> zipWith (curry f) x y where _ = isVar f error = not (elem x y) ==> notElem x y
hlint.cabal view
@@ -1,7 +1,7 @@ cabal-version:      >= 1.6 build-type:         Simple name:               hlint-version:            1.8.42+version:            1.8.43 license:            BSD3 license-file:       LICENSE category:           Development
hlint.htm view
@@ -247,6 +247,19 @@ 	<li><b>Removes error</b> - for example <tt>foldr1 (&&)</tt> suggests <tt>and</tt> including the note "Removes error on []". The new code will produce <tt>True</tt> on the empty list, while the old code would raise an error. Unless you are relying on the exception thrown by the empty list, this hint is safe - and if you do rely on the exception, you would be advised to add a comment. </ul> +<h3 id="error_vs_warning">What is the difference between error and warning?</h3>++<p>+	Every hint has a severity level:+</p>+<ul>+	<li><b>Error</b> - for example <tt>concat (map f x)</tt> suggests <tt>concatMap f x</tt> as an "error" severity hint. From a style point of view, you should always replace a combination of <tt>concat</tt> and <tt>map</tt> with <tt>concatMap</tt>. Note that both expressions are equivalent - HLint is reporting an error in style, <i>not</i> an actual error in the code.</li>+	<li><b>Warning</b> - for example <tt>x !! 0</tt> suggests <tt>head x</tt> as a "warning" severity hint. Typically <tt>head</tt> is a simpler way of expressing the first element of a list, especially if you are treating the list inductively. However, in the expression <tt>f (x !! 4) (x !! 0) (x !! 7)</tt>, replacing the middle argument with <tt>head</tt> makes it harder to follow the pattern, and is probably a bad idea. Warning hints are often worthwhile, but should not be applied blindly.</li>+</ul>+<p>+	The difference between error and warning is one of personal taste, typically my personal taste. If you already have a well developed sense of Haskell style, you should ignore the difference. If you are a beginner Haskell programmer you may wish to focus on error hints before warning hints.+</p>+ <h2 id="customization">Customizing the hints</h2>  <p>
src/HSE/Match.hs view
@@ -50,8 +50,8 @@     fromNamed :: a -> String  -isCon (x:_) = isUpper x || x == ':'-isCon _ = False+isCtor (x:_) = isUpper x || x == ':'+isCtor _ = False  isSym (x:_) = not $ isAlpha x || x `elem` "_'" isSym _ = False@@ -64,7 +64,7 @@     fromNamed _ = ""          toNamed "[]" = List an []-    toNamed x | isCon x = Con an $ toNamed x+    toNamed x | isCtor x = Con an $ toNamed x               | otherwise = Var an $ toNamed x  instance Named (QName S) where@@ -109,7 +109,7 @@     fromNamed (PApp _ x []) = fromNamed x     fromNamed _ = "" -    toNamed x | isCon x = PApp an (toNamed x) []+    toNamed x | isCtor x = PApp an (toNamed x) []               | otherwise = PVar an $ toNamed x  @@ -122,7 +122,7 @@ instance Named (QOp S) where     fromNamed (QVarOp _ x) = fromNamed x     fromNamed (QConOp _ x) = fromNamed x-    toNamed x | isCon x = QConOp an $ toNamed x+    toNamed x | isCtor x = QConOp an $ toNamed x               | otherwise = QVarOp an $ toNamed x  instance Named (Match S) where
src/HSE/Util.hs view
@@ -70,6 +70,7 @@ -- is* :: Exp_ -> Bool -- is* :: Decl_ -> Bool isVar Var{} = True; isVar _ = False+isCon Con{} = True; isCon _ = False isApp App{} = True; isApp _ = False isInfixApp InfixApp{} = True; isInfixApp _ = False isList List{} = True; isList _ = False
src/Hint/Lambda.hs view
@@ -33,9 +33,9 @@ f = flip op x f = foo (flip (*) x) -- (* x) f = foo (flip (-) x)-f = foo (\x y -> fun x y) -- fun+f = foo (\x y -> fun x y) -- @Error fun f = foo (\x y -> x + y) -- (+)-f = foo (\x -> x * y) -- (* y)+f = foo (\x -> x * y) -- @Warning (* y) f = foo (\x -> x # y) f = foo (\x -> \y -> x x y y) -- \x y -> x x y y f = foo (\x -> \x -> foo x x) -- \_ x -> foo x x@@ -58,6 +58,7 @@ foo = [\m x -> insert x x m] foo a b c = bar (flux ++ quux) c where flux = a -- foo a b = bar (flux ++ quux) foo a b c = bar (flux ++ quux) c where flux = c+yes = foo (\x -> Just x) -- @Error Just </TEST> -} @@ -96,7 +97,7 @@ lambdaExp p o@(Paren _ (App _ (App _ (view -> Var_ "flip") (Var _ x)) y)) | allowRightSection $ fromNamed x =     [warn "Use section" o $ RightSection an (QVarOp an x) y] lambdaExp p o@Lambda{} | maybe True (not . isInfixApp) p, res <- niceLambda [] o, not $ isLambda res =-    [warn "Avoid lambda" o res]+    [(if isVar res || isCon res then err else warn) "Avoid lambda" o res] lambdaExp p o@(Lambda _ _ x) | isLambda (fromParen x) && maybe True (not . isLambda) p =     [warn "Collapse lambdas" o $ uncurry (Lambda an) $ fromLambda o] lambdaExp _ _ = []