Haskell:如何告诉hlint不要:`警告:使用字符串文字`
我有一个单元测试文件:Haskell:如何告诉hlint不要:`警告:使用字符串文字`,haskell,hlint,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'] 我试过各种不同的置换法
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…
,将警告更改为警告
什么是魔法?你需要用另一种方式来写布拉格语。经过反复试验,我得出以下结论:
module Test where
import Data.Char(toUpper)
{-# ANN module "HLint: ignore Use string literal" #-}
main :: IO ()
main = putStrLn ['a','b','c']
请注意,您必须编写“模块”
,而不是模块的名称同意@MoFu的解决方案
hlint还支持忽略带有参数的特定警告
hlint -i 'Use string literal' [filename]
将其添加到参数或别名中,因此忽略此警告,但不要中断代码
顺便说一句,句法支持论据。行得通-谢谢。HLint文档对此不清楚。对于函数上的pragmas,它说:{-#ANN myFunction“HLint:ignore”#-}
。对于模块上的pragmas,它说:{-#ANN module“HLint:ignore Eta reduce”#-}
,所以我不清楚我是否应该编写模块
或类似我的模块
@haroldcarr。没有明确说明,这是对的。您可以从以下事实中得出结论:第一个字母是小写字母,模块名称以大写字母开头。另外,如果你能接受我的回答,那就太好了。我已经将文档更新为:{-#ANN module“HLint:ignore Eta reduce”#-}-忽略此模块中的所有Eta reduce建议(按字面意思使用模块,而不是模块名称)。它们是git格式的,但是docs链接仍然会将您带到过时的DARC。我提出了一个错误来解决这个问题。莫夫:当然是大写@neil mitchell:很好,显式-谢谢。看起来对于重载字符串
,您可能还需要显式类型签名。我刚才不得不这么做:{-#ANN validMonetaryChars(“HLint:ignore-Use-String”::Text){-}
谢谢。我将vim中的hlint与ale一起使用,我想忽略有关重复的警告,所以我做了如下操作:让g:ale_linters={'haskell':['hlint-I“减少重复”],}
。
hlint -i 'Use string literal' [filename]