Automatically Apply HLint Suggestions

Posted on November 22, 2015

Users upgrading to hlint 1.9.23 will now be able to take advantage of the new --refactor flag which by invoking the refactor executable supplied by apply-refact can automatically apply suggestions.





Getting Started

cabal install hlint cabal install apply-refact hlint --refactor myfile.hs

To take advantage of this flag users also need to install the refactor executable which is provided by apply-refact . Users can directly invoke refactor if they wish but it is easier to invoke it via hlint, passing any extra options with the --refactor-options flag.

HLint will by default apply all suggestions without any prompts to the user and output the result on stdout.





If you’re feeling cautious, the -s flag will prompt you before applying each refactoring.





If you’re feeling brave, the -i flag will perform the refactoring in place.





The final option which is useful for tool writers is the --pos flag which specifies the region to which hints should be applied to.





Editor Integration

There are plugins availible for vim, emacs and atom. Moritz Kiefer has already helped me with the emacs plugin, pull requests to clean up the other two plugins would be greatly appreciated.

Reporting Bugs

If you find that the program gives you an unexpected result then please report a bug to the issue tracker. Please also include the output of hlint --serialise and the input file.

There are a few known problems with CPP and a few corner cases which are not handled by the underlying library but for most users, a pain-free experience is expected.

Known Issues