HLint 可以自动执行建议的编辑吗?

Can HLint automatically do suggested edits?

HLint 给出了如何改进源代码的建议。但是,考虑到建议的性质,我想知道是否可以自动应用这些建议。

是否可以自动应用 hlint 提出的建议?

您必须使用 --refactor 并在 $PATH 中安装 refactor 可执行文件。有关详细信息,请参阅 hlint's README

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 the refactor executable on you path. refactor is provided by the apply-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.

请注意,hlint 不会以递归方式应用转换,因此可能需要额外的 --refactor。话虽这么说,请确保在应用 hlint --refactor 之前 commit/save 并在之后测试您的代码,因为这些更改可能会破坏您的代码,特别是如果您使用 Rank2Types 或 seq.

为了补充 Zeta 的回答,我使用了一些额外的标志来执行就地重构:

hlint  --refactor --refactor-options="--inplace" path/to/your/File.hs

有时您只想应用某种提示,这可以通过传递 -o 标志来完成,例如:

hlint  -o="Use fewer imports" --refactor --refactor-options="--inplace" 

据我所知,建议的重构需要在每个文件的基础上完成。