Description
First, some pointers. I discovered this issue while investigating a bug against Splint, a GHC plugin that uses HLint: tfausak/splint#9. I think this issue is related to both #143 and #98.
The shortest way to state this problem is that I think calling autoSettings
(or argsSettings
) behaves differently than calling hlint
. In particular any arguments specified in the configuration file seem to be ignored. For example, consider the following Haskell module:
-- Main.hs
import Text.RawString.QQ -- from raw-strings-qq
main = print [r||]
Clearly it needs the QuasiQuotes
language extension in order to compile. No problem, you can add that to your HLint configuration. To wit:
# .hlint.yaml
- arguments: [ -XQuasiQuotes ]
And indeed everything works fine that way. You can run hlint
through your shell, or you can run Language.Haskell.HLint.hlint
and it will succeed.
The problem comes when you try to split apart reading the settings from linting the file. I'm not terribly familiar with HLint's internals, but it felt right to call autoSettings
followed by parseModuleEx
to roughly recreate HLint's command-line interface. Unfortunately that does not work:
>>> (parseFlags, _, _) <- autoSettings
>>> result <- parseModuleEx parseFlags "Main.hs" Nothing
>>> :sprint result
result = Left (ParseError _ _ _)
You can see that it fails because it tries to parse the module without quasi-quotes enabled. Explicitly enabling quasi-quotes works fine:
>>> (parseFlags, _, _) <- argsSettings [ "-XQuasiQuotes" ]
>>> result <- parseModuleEx parseFlags "Main.hs" Nothing
>>> :sprint result
result = Right (hlint-3.1.6:GHC.All.ModuleEx _ (_,_))
Clearly one solution to this problem is to simply call hlint
and avoid loading the settings separately. For my use case that's not ideal, since loading the settings takes a small but appreciable amount of time. I'd prefer to load the settings once, and then lint a bunch of files with those settings.
So ultimately my question is this: Is it possible to load HLint's settings properly using its exposed API? If not, could autoSettings
(really argsSettings
) be made to work the same as hlint
? Thanks!