Skip to content

Commit b435365

Browse files
re-add file
1 parent f77df23 commit b435365

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/Hint/PatternWildCard.hs

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{-
2+
Warn against wildcards in pattern
3+
4+
<TEST>
5+
foo (case x of { Foo _ -> spam }) -- @Ignore ???
6+
case x of { Foo (Spam (Eggs _)) -> spam } -- @Ignore ???
7+
case x of { Foo _ -> spam } -- @Ignore ???
8+
case x of { Foo bar -> spam }
9+
foo (case x of { Foo bar -> spam })
10+
</TEST>
11+
-}
12+
13+
module Hint.PatternWildCard (patternWildCardHint)
14+
where
15+
16+
import Hint.Type (DeclHint, ignoreNoSuggestion, Idea)
17+
import GHC.Hs
18+
import GHC.Types.SrcLoc
19+
import Data.Generics.Uniplate.DataOnly
20+
21+
patternWildCardHint :: DeclHint
22+
patternWildCardHint _ _ code = concatMap inspectCode $ childrenBi code
23+
24+
inspectCode :: LHsExpr GhcPs -> [Idea]
25+
inspectCode (L _ ((HsCase _ _ (MG _ (L _ cases) _)))) = concatMap inspectCase cases
26+
inspectCode o = concatMap inspectCode $ children o
27+
28+
inspectCase :: LMatch GhcPs (LHsExpr GhcPs) -> [Idea]
29+
inspectCase c@(L _ (Match _ _ pats _)) = concatMap inspectPat pats
30+
31+
inspectPat :: LPat GhcPs -> [Idea]
32+
inspectPat c@(L _ (WildPat _)) = [ignoreNoSuggestion "Don't use wildcard in pattern match" (reLoc c)]
33+
inspectPat o = concatMap inspectPat $ children o

0 commit comments

Comments
 (0)