forked from ndmitchell/hlint
-
Notifications
You must be signed in to change notification settings - Fork 0
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
4620d86
commit 8d330e7
Showing
4 changed files
with
74 additions
and
1 deletion.
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
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
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
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,38 @@ | ||
{-# LANGUAGE CPP #-} | ||
{- | ||
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] | ||
#if __GLASGOW_HASKELL__ >= 906 | ||
inspectCode (L _ ((HsCase _ _ (MG _ (L _ cases))))) = concatMap inspectCase cases | ||
#else | ||
inspectCode (L _ ((HsCase _ _ (MG _ (L _ cases) _)))) = concatMap inspectCase cases | ||
#endif | ||
inspectCode o = concatMap inspectCode $ children o | ||
|
||
inspectCase :: LMatch GhcPs (LHsExpr GhcPs) -> [Idea] | ||
inspectCase c@(L _ (Match _ _ (L _ 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 |