HLint gives suggestion how one can improve source code. However, given the nature of the suggestions, I wonder whether it's possible to automatically apply those suggestions.
Is it possible to automatically apply suggestions proposed by hlint
?
You have to use --refactor
and have the refactor
executable in your $PATH
. See hlint's README for more information:
Automatically Applying Hints
By supplying the
--refactor
flag hlint can automatically apply most suggestions. Instead of a list of hints, hlint will instead output the refactored file on stdout. In order to do this, it is necessary to have therefactor
executable on you path.refactor
is provided by theapply-refact
package, it uses the GHC API in order to transform source files given a list of refactorings to apply. Hlint directly calls the executable to apply the suggestions.
Note that hlint doesn't apply transformations recursively, so additional --refactor
could be necessary. That being said, make sure to commit/save before you apply hlint --refactor
and test your code afterwards, since the changes might break your code, especially if you use Rank2Types or seq
.