Skip to content

Commit

Permalink
re-add file
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjudkins committed Apr 12, 2023
1 parent f77df23 commit b435365
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/Hint/PatternWildCard.hs
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

0 comments on commit b435365

Please sign in to comment.