Saurabh Nanda
Saurabh Nanda

Reputation: 6793

How to write complex / multi-line hlint rules?

What's the way to match the following code-pattern...

do 
  x <- createModel a b
  case x of
    Left e -> throwM $ ValidationErrors e
    Right y -> ...

...and suggest the following replacement:

withThrow $ createModel a b

I tried the following, but it doesn't work:

hint: {lhs: "do {x <- createModel v w; case x of Left e -> throwM $ ValidationErrors e}", rhs: "withThrow $ createModel v w"}

Upvotes: 1

Views: 118

Answers (1)

Neil Mitchell
Neil Mitchell

Reputation: 9250

The problem is that HLint matching is expression based, whereas the rule you're trying to define is really statement based - you want to match the two statements anywhere adjacently in a do. It's possible HLint could be modified to do that, and you think that would be useful, please raise an HLint issue.

Upvotes: 1

Related Questions