Skip to content

Loading settings differs between library and executable #1232

Open
@tfausak

Description

@tfausak

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions