{-|
/WARNING: This module represents the old version of the HLint API./
/It will be deleted in favour of "Language.Haskell.HLint3" in the next major version./

This module provides a library interface to HLint, strongly modelled on the command line interface.
-}

module Language.Haskell.HLint(hlint, Suggestion, suggestionLocation, suggestionSeverity, Severity(..)) where

import qualified HLint
import Config.Type
import Idea
import HSE.All


-- | This function takes a list of command line arguments, and returns the given suggestions.
--   To see a list of arguments type @hlint --help@ at the console.
--   This function writes to the stdout/stderr streams, unless @--quiet@ is specified.
--
--   As an example:
--
-- > do hints <- hlint ["src", "--ignore=Use map","--quiet"]
-- >    when (length hints > 3) $ error "Too many hints!"
hlint :: [String] -> IO [Suggestion]
hlint :: [String] -> IO [Suggestion]
hlint = ([Idea] -> [Suggestion]) -> IO [Idea] -> IO [Suggestion]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Idea -> Suggestion) -> [Idea] -> [Suggestion]
forall a b. (a -> b) -> [a] -> [b]
map Idea -> Suggestion
Suggestion_) (IO [Idea] -> IO [Suggestion])
-> ([String] -> IO [Idea]) -> [String] -> IO [Suggestion]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [String] -> IO [Idea]
HLint.hlint



-- | A suggestion - the @Show@ instance is of particular use.
newtype Suggestion = Suggestion_ {Suggestion -> Idea
fromSuggestion :: Idea}
                     deriving (Suggestion -> Suggestion -> Bool
(Suggestion -> Suggestion -> Bool)
-> (Suggestion -> Suggestion -> Bool) -> Eq Suggestion
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Suggestion -> Suggestion -> Bool
$c/= :: Suggestion -> Suggestion -> Bool
== :: Suggestion -> Suggestion -> Bool
$c== :: Suggestion -> Suggestion -> Bool
Eq,Eq Suggestion
Eq Suggestion =>
(Suggestion -> Suggestion -> Ordering)
-> (Suggestion -> Suggestion -> Bool)
-> (Suggestion -> Suggestion -> Bool)
-> (Suggestion -> Suggestion -> Bool)
-> (Suggestion -> Suggestion -> Bool)
-> (Suggestion -> Suggestion -> Suggestion)
-> (Suggestion -> Suggestion -> Suggestion)
-> Ord Suggestion
Suggestion -> Suggestion -> Bool
Suggestion -> Suggestion -> Ordering
Suggestion -> Suggestion -> Suggestion
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Suggestion -> Suggestion -> Suggestion
$cmin :: Suggestion -> Suggestion -> Suggestion
max :: Suggestion -> Suggestion -> Suggestion
$cmax :: Suggestion -> Suggestion -> Suggestion
>= :: Suggestion -> Suggestion -> Bool
$c>= :: Suggestion -> Suggestion -> Bool
> :: Suggestion -> Suggestion -> Bool
$c> :: Suggestion -> Suggestion -> Bool
<= :: Suggestion -> Suggestion -> Bool
$c<= :: Suggestion -> Suggestion -> Bool
< :: Suggestion -> Suggestion -> Bool
$c< :: Suggestion -> Suggestion -> Bool
compare :: Suggestion -> Suggestion -> Ordering
$ccompare :: Suggestion -> Suggestion -> Ordering
$cp1Ord :: Eq Suggestion
Ord)

instance Show Suggestion where
    show :: Suggestion -> String
show = Idea -> String
forall a. Show a => a -> String
show (Idea -> String) -> (Suggestion -> Idea) -> Suggestion -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Suggestion -> Idea
fromSuggestion

-- | From a suggestion, extract the file location it refers to.
suggestionLocation :: Suggestion -> SrcLoc
suggestionLocation :: Suggestion -> SrcLoc
suggestionLocation = SrcSpan -> SrcLoc
forall si. SrcInfo si => si -> SrcLoc
getPointLoc (SrcSpan -> SrcLoc)
-> (Suggestion -> SrcSpan) -> Suggestion -> SrcLoc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Idea -> SrcSpan
ideaSpan (Idea -> SrcSpan) -> (Suggestion -> Idea) -> Suggestion -> SrcSpan
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Suggestion -> Idea
fromSuggestion


-- | From a suggestion, determine how severe it is.
suggestionSeverity :: Suggestion -> Severity
suggestionSeverity :: Suggestion -> Severity
suggestionSeverity = Idea -> Severity
ideaSeverity (Idea -> Severity)
-> (Suggestion -> Idea) -> Suggestion -> Severity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Suggestion -> Idea
fromSuggestion