Question

I have a unit test file:

module X04PatMatTest where

import AssertError
import Test.HUnit
import X04PatMat

...

and hlint complains:

X04PatMatTest.hs:15:69: Warning: Use string literal 
Found:
  ['a', 'b', 'd']
Why not:
  "abd"

for various reasons, I really want to put ['a', 'b', 'd'] in the test code.

I have tried various permuatations of

{-# ANN X04PatMatTest "HLint: ignore Warning: Use string literal" #-}

like putting the pragma as the first line of the file, after the module declaration, with the name module instead of X04..., changing the Warning to warn ...

What is the magic?

Was it helpful?

Solution

You need to write the pragma in another way. After some trial and error I came up with the following:

module Test where

import Data.Char(toUpper)

{-# ANN module "HLint: ignore Use string literal" #-}
main :: IO ()
main = putStrLn ['a','b','c']

note that you have to write "module" and not the name of the module

OTHER TIPS

Agree with @MoFu's solution.

hlint also support ignore specific warning with arguments.

hlint -i 'Use string literal' [filename]

add this to arguments or aliases, so ignore this warning, but not break your code.

By the way, synatastic support arguments.


With recent (>2019) hlint, you can use the simpler syntax {- HLINT ignore "some hint" -}:

module Test where

import Data.Char(toUpper)

{- HLINT ignore "Use string literal" -}
main :: IO ()
main = putStrLn ['a','b','c']

Unlike ANN, this can be placed anywhere in the file, and there's no need for annotating it as String if you use OverloadedStrings, and it will not lead to increased compile time.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top