-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f77df23
commit b435365
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{- | ||
Warn against wildcards in pattern | ||
<TEST> | ||
foo (case x of { Foo _ -> spam }) -- @Ignore ??? | ||
case x of { Foo (Spam (Eggs _)) -> spam } -- @Ignore ??? | ||
case x of { Foo _ -> spam } -- @Ignore ??? | ||
case x of { Foo bar -> spam } | ||
foo (case x of { Foo bar -> spam }) | ||
</TEST> | ||
-} | ||
|
||
module Hint.PatternWildCard (patternWildCardHint) | ||
where | ||
|
||
import Hint.Type (DeclHint, ignoreNoSuggestion, Idea) | ||
import GHC.Hs | ||
import GHC.Types.SrcLoc | ||
import Data.Generics.Uniplate.DataOnly | ||
|
||
patternWildCardHint :: DeclHint | ||
patternWildCardHint _ _ code = concatMap inspectCode $ childrenBi code | ||
|
||
inspectCode :: LHsExpr GhcPs -> [Idea] | ||
inspectCode (L _ ((HsCase _ _ (MG _ (L _ cases) _)))) = concatMap inspectCase cases | ||
inspectCode o = concatMap inspectCode $ children o | ||
|
||
inspectCase :: LMatch GhcPs (LHsExpr GhcPs) -> [Idea] | ||
inspectCase c@(L _ (Match _ _ pats _)) = concatMap inspectPat pats | ||
|
||
inspectPat :: LPat GhcPs -> [Idea] | ||
inspectPat c@(L _ (WildPat _)) = [ignoreNoSuggestion "Don't use wildcard in pattern match" (reLoc c)] | ||
inspectPat o = concatMap inspectPat $ children o |