简体   繁体   中英

How can I use annotations to customize HLint and mark my Haskell package as Safe?

In my package I have several annotations to help customize my use of hlint :

{-# ANN module ("HLint: ignore Use infix"::String) #-}
{-# ANN module ("HLint: ignore Use mappend"::String) #-}
{-# ANN module ("HLint: ignore Use fmap"::String) #-}
{-# ANN module ("HLint: error Redundant $"::String) #-}
{-# ANN module ("HLint: ignore Use ."::String) #-}

But when I try to mark my package as Safe with

{-# LANGUAGE Safe #-}

I get

    • Annotations are not compatible with Safe Haskell.
      See https://ghc.haskell.org/trac/ghc/ticket/10826
    • In the annotation:
        {-# ANN module ("HLint: ignore Use ." :: String) #-}
   |
80 | {-# ANN module ("HLint: ignore Use ."::String) #-}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

while with the annotations removed, I can build and test as Safe without errors.

Is there an alternative way to customize Hlint that allows my package to be marked as Safe?

Instead of using ANN pragmas, you can use either:

{-# HLINT ignore "Use mappend" #-}

or:

{- HLINT ignore "Use mappend" -}

The former will trigger a warning from GHC about an unknown pragma.

See also:

https://github.com/ndmitchell/hlint#ignoring-hints

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM