haskellvisual-studio-codehaskell-stackhlint

Unrecognised HLINT pragma in Haskell


I'm trying to disable some warnings that HLint is giving me. According to docs I should be able to add a pragma to the top of my file. So I tried the following:

{-# HLINT ignore #-}
module Main where

Which however gives me an error when running stack build:

/Users/nene/somedir/src/Main.hs:1:1: warning: [-Wunrecognised-pragmas]
    Unrecognised pragma
  |
1 | {-# HLINT ignore #-}
  | ^^^

Seems like the pragma actually works in my editor (VSCode with "Haskell" extension), but is not recognized when running stack.


Solution

  • If you want to use a pragma without any warnings, you can use the ANN pragma like this:

    {-# ANN module "HLint: ignore" #-}
    

    However I would recommend using a regular comment instead of a pragma:

    {- HLINT ignore -}
    

    I prefer regular comments because they don't have weird rules like pragmas do. In fact the documentation notes:

    For ANN pragmas it is important to put them after any import statements. If you have the OverloadedStrings extension enabled you will need to give an explicit type to the annotation, e.g. {-# ANN myFunction ("HLint: ignore" :: String) #-}. The ANN pragmas can also increase compile times or cause more recompilation than otherwise required, since they are evaluated by TemplateHaskell.

    For {-# HLINT #-} pragmas GHC may give a warning about an unrecognised pragma, which can be suppressed with -Wno-unrecognised-pragmas.