hlint icon indicating copy to clipboard operation
hlint copied to clipboard

Setting Language Disables Other Extensions

Open Burtannia opened this issue 1 year ago • 7 comments

While configuring my .hlint.yaml file for my Yesod project I ran into a strange issue. I decided to dump all my default-extensions as arguments into hlint just to ensure correct parsing. I'm using GHC2021 so I also wanted to pass -XGHC2021. The minimal example I can give is using template haskell:

- arguments: [
  --color,
  --cpp-simple,
  -XGHC2021,
  -XTemplateHaskell,
]

This should work just fine to my understanding, in fact -XTemplateHaskell is probably redundant because I believe hlint automatically enables it. Either way this produces warnings all over the place of the form:

src/Handler/Profile.hs:12:10-31: Suggestion: Redundant bracket
Found:
  do setTitle . toHtml $ userIdent user <> "'s User page"
    $ (widgetFile "profile")
Perhaps:
  do setTitle . toHtml $ userIdent user <> "'s User page"
    $ widgetFile "profile"

Removing -XGHC2021 from the arguments list fixes the issue and the warnings no longer show. My guess is that selecting the language version ignores any other extensions. The issue is also present using -XHaskell2010.

As an aside to this, it would be nice if hlint could automatically detect and use the language version / default-extensions from package.yaml to avoid the need for these arguments entirely. This seems to happen via HLS in VSCode but does not happen when running hlint manually via the command line.

Burtannia avatar Jun 26 '24 01:06 Burtannia

Just ran into this too, specifically with GHC2021 & TemplateHaskell; (hlint 3.6.1)

LiamGoodacre avatar Oct 31 '24 13:10 LiamGoodacre

if you pass nothing, hlint will decide for itself what extensions to enable based on the principle of being able to parse as broad a set of haskell as possible.

if you pass -XGHC2021 then that defines the set of extensions that are enabled and nothing more. to get the GHC2021 extensions and TemplateHaskell then -XGHC201 -XTemplateHaskell should do it

(i should point out, this is the behavior on the command line i'm talking about - i haven't looked at what happens with arguments passed in .hlint.yaml files before - maybe there's an issue with that?)

shayne-fletcher avatar Oct 31 '24 14:10 shayne-fletcher

to get the GHC2021 extensions and TemplateHaskell then -XGHC201 -XTemplateHaskell should do it

This doesn't appear to work (3.6.1) neither as command line arguments nor arguments in the yaml file.

Example.hs

module Example where

example = $(something)

With command args

∀ hlint -XGHC2021 -XTemplateHaskell Example.hs
Example.hs:3:11: Error: Parse error: on input `$'
Found:
    module Example where

  > example = $(something)


1 error

With config file

example.hlint.yaml

- arguments:
    - -XGHC2021
    - -XTemplateHaskell
∀ hlint --hint=example.hlint.yaml Example.hs
Example.hs:3:11: Error: Parse error: on input `$'
Found:
    module Example where

  > example = $(something)


1 error

Only TemplateHaskell (no GHC2021)

∀ hlint -XTemplateHaskell Example.hs
No hints

LiamGoodacre avatar Oct 31 '24 15:10 LiamGoodacre

quick test here with v3.8 on the command line seems to confirm the reported issue

shayne-fletcher avatar Oct 31 '24 15:10 shayne-fletcher

i still haven't quite worked out what is up with this but i have a workaround: hlint -XGHC2021 -XTemplateHaskell -XTemplateHaskellQuotes ...

shayne-fletcher avatar Nov 01 '24 14:11 shayne-fletcher

i put a fix up for this in https://github.com/ndmitchell/hlint/pull/1619. bit surprised, i knew that we'd looked at extensionImplications before but i couldn't find anywhere we went and used it!

shayne-fletcher avatar Nov 02 '24 17:11 shayne-fletcher

Thanks a lot for fixing this @shayne-fletcher !

LiamGoodacre avatar Dec 16 '24 16:12 LiamGoodacre