hlint
hlint copied to clipboard
Pattern synonyms rules
I would like to use HLint to suggest using custom pattern synonyms.
My use case is that swarm defines several patterns for matching types in its language and I would like HLint to remind me about them when pattern matching.
Another less important example is the pattern for pressed Key
:
pattern Key c = VtyEvent (EvKey (KChar c) [])
I would like to write a HLint rule like this:
- warning: {lhs: "VtyEvent (EvKey (KChar c) [])", rhs: "Key c"}
But it only works on the right-hand side and not on the left:
f (VtyEvent (EvKey (KChar c) [])) = c
-- No warning.
g c = VtyEvent (EvKey (KChar c) [])
-- Warning: Use Key
-- Found:
-- VtyEvent (EvKey (KChar c) [])
-- Perhaps:
-- Key c
I tried including the function and right-hand side in the rule:
- warning: {lhs: 'f (VtyEvent (EvKey (KChar c) [])) = x', rhs: 'f (Key c) = x'} # does not parse
But HLint said that Aeson would not parse =
(or ->
).
Is there a way to write this rule now or would that be a new feature?
Currently the LHS/RHS matches are restricted to expressions. People have asked for this to be generalised to types, #449, and doing so for patterns too would be a reasonable extension.