Haskell:如何告诉hlint不要:`警告:使用字符串文字`

时间:2013-10-08 01:43:25

标签: haskell hlint

我有一个单元测试文件:

module X04PatMatTest where

import AssertError
import Test.HUnit
import X04PatMat

...

和hlint抱怨:

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

出于各种原因,我真的想把['a', 'b', 'd']放在测试代码中。

我尝试了各种各样的

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

比如将pragma作为文件的第一行,在模块声明之后,使用名称module而不是X04...,将Warning更改为warn。 ..

什么是魔法?

3 个答案:

答案 0 :(得分:17)

你需要以另一种方式编写pragma。经过一些反复试验后,我想出了以下内容:

module Test where

import Data.Char(toUpper)

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

请注意,您必须编写"module"而不是模块的名称

答案 1 :(得分:1)

同意@ MoFu的解决方案。

hlint还支持忽略带参数的特定警告。

hlint -i 'Use string literal' [filename]

将其添加到参数或别名中,因此请忽略此警告,但不要破坏您的代码。

顺便说一下,synatastic支持论点。

答案 2 :(得分:0)


借助最近 (>2019) 提示,您可以使用更简单的语法 {- HLINT ignore "some hint" -}

module Test where

import Data.Char(toUpper)

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

ANN不同的是,它可以放在文件的任意位置,使用String就不需要注释为OverloadedStrings,也不会导致编译时间增加.