Safe Haskell | None |
---|
WARNING: This module represents the evolving second version of the HLint API. It will be renamed to drop the "3" in the next major version.
This module provides a way to apply HLint hints. As an example of approximating the hlint
experience:
(flags, classify, hint) <-autoSettings
Right m <-parseModuleEx
flags "MyFile.hs" Nothing print $applyHints
classify hint [m]
- applyHints :: [Classify] -> Hint -> [(Module SrcSpanInfo, [Comment])] -> [Idea]
- data Idea = Idea {}
- data Severity
- data Note
- data Classify = Classify {}
- getHLintDataDir :: IO FilePath
- autoSettings :: IO (ParseFlags, [Classify], Hint)
- findSettings :: (String -> IO (FilePath, Maybe String)) -> Maybe String -> IO ([Fixity], [Classify], [Either HintBuiltin HintRule])
- readSettingsFile :: Maybe FilePath -> String -> IO (FilePath, Maybe String)
- data HintBuiltin
- = HintList
- | HintListRec
- | HintMonad
- | HintLambda
- | HintBracket
- | HintNaming
- | HintStructure
- | HintImport
- | HintPragma
- | HintExtensions
- | HintUnsafe
- | HintDuplicate
- | HintComment
- data HintRule = HintRule {
- hintRuleSeverity :: Severity
- hintRuleName :: String
- hintRuleScope :: Scope
- hintRuleLHS :: Exp SrcSpanInfo
- hintRuleRHS :: Exp SrcSpanInfo
- hintRuleSide :: Maybe (Exp SrcSpanInfo)
- hintRuleNotes :: [Note]
- data Hint = Hint {
- hintModules :: [(Scope, Module SrcSpanInfo)] -> [Idea]
- hintModule :: Scope -> Module SrcSpanInfo -> [Idea]
- hintDecl :: Scope -> Module SrcSpanInfo -> Decl SrcSpanInfo -> [Idea]
- hintComment :: Comment -> [Idea]
- resolveHints :: [Either HintBuiltin HintRule] -> Hint
- data Scope
- scopeCreate :: Module SrcSpanInfo -> Scope
- scopeMatch :: (Scope, QName SrcSpanInfo) -> (Scope, QName SrcSpanInfo) -> Bool
- scopeMove :: (Scope, QName SrcSpanInfo) -> Scope -> QName SrcSpanInfo
- parseModuleEx :: ParseFlags -> FilePath -> Maybe String -> IO (Either ParseError (Module SrcSpanInfo, [Comment]))
- defaultParseFlags :: ParseFlags
- parseFlagsAddFixities :: [Fixity] -> ParseFlags -> ParseFlags
- data ParseError = ParseError {
- parseErrorLocation :: SrcLoc
- parseErrorMessage :: String
- parseErrorContents :: String
- data ParseFlags = ParseFlags {
- encoding :: TextEncoding
- cppFlags :: CppFlags
- hseFlags :: ParseMode
- data CppFlags
Documentation
applyHints :: [Classify] -> Hint -> [(Module SrcSpanInfo, [Comment])] -> [Idea]Source
Idea data type
An idea suggest by a Hint
.
Idea | |
|
How severe an issue is.
A note describing the impact of the replacement.
IncreasesLaziness | The replacement is increases laziness, for example replacing |
DecreasesLaziness | The replacement is decreases laziness, for example replacing |
RemovesError String | The replacement removes errors, for example replacing |
ValidInstance String String | The replacement assumes standard type class lemmas, a hint with the note |
Note String | An arbitrary note. |
Settings
How to classify an Idea
. If any matching field is ""
then it matches everything.
Classify | |
|
getHLintDataDir :: IO FilePathSource
Get the Cabal configured data directory of HLint.
autoSettings :: IO (ParseFlags, [Classify], Hint)Source
The function produces a tuple containg ParseFlags
(for parseModuleEx
),
and Classify
and Hint
for applyHints
.
It approximates the normal HLint configuration steps, roughly:
- Use
findSettings
withreadSettingsFile
to find and load the HLint settings files. - Use
parseFlagsAddFixities
andresolveHints
to transform the outputs offindSettings
.
If you want to do anything custom (e.g. using a different data directory, storing intermediate outputs, loading hints from a database) you are expected to copy and paste this function, then change it to your needs.
findSettings :: (String -> IO (FilePath, Maybe String)) -> Maybe String -> IO ([Fixity], [Classify], [Either HintBuiltin HintRule])Source
Given a function to load a module (typically readSettingsFile
), and a module to start from
(defaults to HLint.HLint
) find the information from all settings files.
readSettingsFile :: Maybe FilePath -> String -> IO (FilePath, Maybe String)Source
Given a directory (or Nothing
to imply getHLintDataDir
), and a mdoule name
(e.g. HLint.Default
), find the settings file associated with it, returning the
name of the file, and (optionally) the contents.
This function looks for all settings files starting with HLint.
in the directory
argument, and all other files relative to the current directory.
Hints
data HintBuiltin Source
A list of the builtin hints wired into HLint. This list is likely to grow over time.
A LHS ==> RHS
style hint rule.
HintRule | |
|
Functions to generate hints, combined using the Monoid
instance.
Hint | |
|
resolveHints :: [Either HintBuiltin HintRule] -> HintSource
Scopes
Data type representing the modules in scope within a module.
Created with scopeCreate
and queried with scopeMatch
and scopeMove
.
Note that the mempty
Scope
is not equivalent to scopeCreate
on an empty module,
due to the implicit import of Prelude
.
scopeCreate :: Module SrcSpanInfo -> ScopeSource
Create a Scope
value from a module, based on the modules imports.
scopeMatch :: (Scope, QName SrcSpanInfo) -> (Scope, QName SrcSpanInfo) -> BoolSource
Given a two names in scopes, could they possibly refer to the same thing. This property is reflexive.
scopeMove :: (Scope, QName SrcSpanInfo) -> Scope -> QName SrcSpanInfoSource
Given a name in a scope, and a new scope, create a name for the new scope that will refer to the same thing. If the resulting name is ambiguous, it picks a plausible candidate.
Haskell-src-exts
parseModuleEx :: ParseFlags -> FilePath -> Maybe String -> IO (Either ParseError (Module SrcSpanInfo, [Comment]))Source
Parse a Haskell module. Applies the C pre processor, and uses best-guess fixity resolution if there are ambiguities.
The filename -
is treated as stdin
. Requires some flags (often defaultParseFlags
), the filename, and optionally the contents of that file.
defaultParseFlags :: ParseFlagsSource
Default value for ParseFlags
.
parseFlagsAddFixities :: [Fixity] -> ParseFlags -> ParseFlagsSource
data ParseError Source
A parse error from parseModuleEx
.
ParseError | |
|