| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Language.Haskell.HLint3
Description
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. If you want to just run hlint in-process
and collect the results see hlint. If you want to approximate the hlint experience with
a more structured API try:
(flags, classify, hint) <-autoSettingsRight m <-parseModuleExflags "MyFile.hs" Nothing print $applyHintsclassify hint [m]
- hlint :: [String] -> IO [Idea]
- applyHints :: [Classify] -> Hint -> [(Module_, [Comment])] -> [Idea]
- data Idea = Idea {
- ideaModule :: String
- ideaDecl :: String
- ideaSeverity :: Severity
- ideaHint :: String
- ideaSpan :: SrcSpan
- ideaFrom :: String
- ideaTo :: Maybe String
- ideaNote :: [Note]
- ideaRefactoring :: [Refactoring SrcSpan]
- data Severity
- = Ignore
- | Suggestion
- | Warning
- | Error
- data Note
- data Classify = Classify {}
- getHLintDataDir :: IO FilePath
- autoSettings :: IO (ParseFlags, [Classify], Hint)
- argsSettings :: [String] -> 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
- data HintRule = HintRule {
- hintRuleSeverity :: Severity
- hintRuleName :: String
- hintRuleScope :: Scope
- hintRuleLHS :: Exp_
- hintRuleRHS :: Exp_
- hintRuleSide :: Maybe Exp_
- hintRuleNotes :: [Note]
- data Hint = Hint {
- hintModules :: [(Scope, Module_)] -> [Idea]
- hintModule :: Scope -> Module_ -> [Idea]
- hintDecl :: Scope -> Module_ -> Decl_ -> [Idea]
- hintComment :: Comment -> [Idea]
- resolveHints :: [Either HintBuiltin HintRule] -> Hint
- data Scope
- scopeCreate :: Module_ -> Scope
- scopeMatch :: (Scope, QName S) -> (Scope, QName S) -> Bool
- scopeMove :: (Scope, QName S) -> Scope -> QName S
- parseModuleEx :: ParseFlags -> FilePath -> Maybe String -> IO (Either ParseError (Module_, [Comment]))
- defaultParseFlags :: ParseFlags
- parseFlagsAddFixities :: [Fixity] -> ParseFlags -> ParseFlags
- data ParseError = ParseError {}
- data ParseFlags = ParseFlags {}
- data CppFlags
Documentation
hlint :: [String] -> IO [Idea] #
This function takes a list of command line arguments, and returns the given hints.
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!"
Warning: The flags provided by HLint are relatively stable, but do not have the same API stability guarantees as the rest of the strongly-typed API. Do not run this function on a your server with untrusted input.
applyHints :: [Classify] -> Hint -> [(Module_, [Comment])] -> [Idea] #
Given a way of classifying results, and a Hint, apply to a set of modules generating a list of Ideas.
The Idea values will be ordered within a file.
Given a set of modules, it may be faster pass each to applyHints in a singleton list.
When given multiple modules at once this function attempts to find hints between modules,
which is slower and often pointless (by default HLint passes modules singularly, using
--cross to pass all modules together).
Idea data type
An idea suggest by a Hint.
Constructors
| Idea | |
Fields
| |
How severe an issue is.
Constructors
| Ignore | The issue has been explicitly ignored and will usually be hidden (pass |
| Suggestion | Suggestions are things that some people may consider improvements, but some may not. |
| Warning | Warnings are suggestions that are nearly always a good idea to apply. |
| Error | Available as a setting for the user. |
A note describing the impact of the replacement.
Constructors
| 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.
Constructors
| Classify | |
Fields
| |
getHLintDataDir :: IO FilePath #
Get the Cabal configured data directory of HLint.
autoSettings :: IO (ParseFlags, [Classify], Hint) #
The function produces a tuple containg ParseFlags (for parseModuleEx),
and Classify and Hint for applyHints.
It approximates the normal HLint configuration steps, roughly:
- Use
findSettingswithreadSettingsFileto find and load the HLint settings files. - Use
parseFlagsAddFixitiesandresolveHintsto 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.
argsSettings :: [String] -> IO (ParseFlags, [Classify], Hint) #
A version of autoSettings which respects some of the arguments supported by HLint.
If arguments unrecognised by HLint are used it will result in an error.
Arguments which have no representation in the return type are silently ignored.
findSettings :: (String -> IO (FilePath, Maybe String)) -> Maybe String -> IO ([Fixity], [Classify], [Either HintBuiltin HintRule]) #
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) #
Given a directory (or Nothing to imply getHLintDataDir), and a module 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 #
A list of the builtin hints wired into HLint. This list is likely to grow over time.
Constructors
| HintList | |
| HintListRec | |
| HintMonad | |
| HintLambda | |
| HintBracket | |
| HintNaming | |
| HintPattern | |
| HintImport | |
| HintPragma | |
| HintExtensions | |
| HintUnsafe | |
| HintDuplicate | |
| HintComment | |
| HintNewType |
Instances
A LHS ==> RHS style hint rule.
Constructors
| HintRule | |
Fields
| |
Functions to generate hints, combined using the Monoid instance.
Constructors
| Hint | |
Fields
| |
resolveHints :: [Either HintBuiltin HintRule] -> Hint #
Transform a list of HintBuiltin or HintRule into a Hint.
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_ -> Scope #
Create a Scope value from a module, based on the modules imports.
scopeMatch :: (Scope, QName S) -> (Scope, QName S) -> Bool #
Given a two names in scopes, could they possibly refer to the same thing. This property is reflexive.
scopeMove :: (Scope, QName S) -> Scope -> QName S #
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_, [Comment])) #
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 :: ParseFlags #
Default value for ParseFlags.
parseFlagsAddFixities :: [Fixity] -> ParseFlags -> ParseFlags #
Given some fixities, add them to the existing fixities in ParseFlags.
data ParseError #
A parse error from parseModuleEx.
Constructors
| ParseError | |
Fields
| |