ndmitchell / hlint

Haskell source code suggestions
Other
1.47k stars 196 forks source link

Hlint gets confused by `import Prelude ()` #460

Open bergmark opened 6 years ago

bergmark commented 6 years ago
$ hlint --version
HLint v2.1.1, (C) Neil Mitchell 2006-2018

This seems to affect custom hints that don't use anything from Prelude (such as the wibble example in the defaults) as well.

Test1.hs

module Test where

import Prelude ()

f = concat $ map (+1) [1]
$ hlint Test.hs
No hints

But it's fine if NoImplicitPrelude is used instead

Test2.hs

{-# LANGUAGE NoImplicitPrelude #-}
module Test where

f = concat $ map (+1) [1]
$ hlint Test2.hs
Test2.hs:4:5: Warning: Use concatMap
Found:
  concat $ map (+ 1) [1]
Why not:
  concatMap (+ 1) [1]

1 hint
ndmitchell commented 6 years ago

Clearly the current state is wrong - these things should be more equivalent. However, do you think that concat/map should hint if you have disabled the Prelude?

bergmark commented 6 years ago

With these examples it would make sense if it didn't trigger, but like i said it also seems to affect non-prelude related hints...

My actual code is the following, where i have Prelude imported through other means:

import Prelude ()
import Prelude.Compat

The awkward thing is that if you add import Prelude () hlint will "stop" linting your files without telling you...

ndmitchell commented 6 years ago

Yep, noted - I was more asking about the future hypothetical solution where all that is fixed.

bergmark commented 6 years ago

Perhaps a workaround for import Prelude (); import Prelude.Compat could be if hlint supported declaring module aliases? This at least solves the issue for projects using base-compat.

ndmitchell commented 6 years ago

Yep, I think we'll need some form of module aliases, as per #434. My inclination is to just name all the common Prelude replacements in the standard HLint install, since those are the common ones.

bergmark commented 6 years ago

sounds good!