| Safe Haskell | None |
|---|
Language.Haskell.HLint2
Description
WARNING: This module represents the evolving second version of the HLint API. It will be renamed to drop the "2" 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) <-autoSettingsRight m <-parseModuleExflags "MyFile.hs" Nothing print $applyHintsclassify hint [m]
- applyHints :: [Classify] -> Hint -> [(Module SrcSpanInfo, [Comment])] -> [Idea]
- data Idea = Idea {}
- data Severity
- data Note
- = IncreasesLaziness
- | DecreasesLaziness
- | RemovesError String
- | ValidInstance String String
- | Note String
- data Classify = Classify {
- classifySeverity :: Severity
- classifyHint :: String
- classifyModule :: String
- classifyDecl :: String
- getHLintDataDir :: IO FilePath
- autoSettings :: IO (ParseFlags, [Classify], Hint)
- findSettings :: FilePath -> FilePath -> Maybe String -> IO ([String], [Module SrcSpanInfo])
- readSettings :: Module SrcSpanInfo -> ([Classify], [HintRule])
- data Hint = Hint {
- hintModules :: [(Scope, Module SrcSpanInfo)] -> [Idea]
- hintModule :: Scope -> Module SrcSpanInfo -> [Idea]
- hintDecl :: Scope -> Module SrcSpanInfo -> Decl SrcSpanInfo -> [Idea]
- hintComment :: Comment -> [Idea]
- builtinHints :: [(String, Hint)]
- data HintRule = HintRule {
- hintRuleSeverity :: Severity
- hintRuleName :: String
- hintRuleScope :: Scope
- hintRuleLHS :: Exp SrcSpanInfo
- hintRuleRHS :: Exp SrcSpanInfo
- hintRuleSide :: Maybe (Exp SrcSpanInfo)
- hintRuleNotes :: [Note]
- hintRules :: [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
- data ParseError = ParseError {
- parseErrorLocation :: SrcLoc
- parseErrorMessage :: String
- parseErrorContents :: String
- data ParseFlags = ParseFlags {}
- data CppFlags
- = NoCpp
- | CppSimple
- | Cpphs CpphsOptions
- data Encoding
- defaultEncoding :: Encoding
- readEncoding :: String -> IO Encoding
- useEncoding :: Handle -> Encoding -> IO ()
Documentation
applyHints :: [Classify] -> Hint -> [(Module SrcSpanInfo, [Comment])] -> [Idea]Source
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 |
| Warning | Warnings are things that some people may consider improvements, but some may not. |
| Error | Errors are suggestions that are nearly always a good idea to apply. |
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
| |
Instances
| Show 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
findSettingsto find and load the HLint settings files. - Use
readSettingsto interpret the settings files, producingHintRulevalues (LHS ==> RHSreplacements) andClassifyvalues to assignSeverityratings to hints. - Use
builtinHintsandhintRulesto generate aHintvalue. - Take all fixities from the
findSettingsmodules and put them in theParseFlags.
findSettings :: FilePath -> FilePath -> Maybe String -> IO ([String], [Module SrcSpanInfo])Source
Given the data directory (where the hlint data files reside, see getHLintDataDir),
and a filename to read, and optionally that file's contents, produce a pair containing:
- Builtin hints to use, e.g.
List, which should be resolved usingbuiltinHints. - A list of modules containing hints, suitable for processing with
readSettings.
Any parse failures will result in an exception.
readSettings :: Module SrcSpanInfo -> ([Classify], [HintRule])Source
Hints
Functions to generate hints, combined using the Monoid instance.
Constructors
| Hint | |
Fields
| |
Instances
| Monoid Hint |
builtinHints :: [(String, Hint)]Source
A list of builtin hints, currently including entries such as "List" and "Bracket".
A LHS ==> RHS style hint rule.
Constructors
| HintRule | |
Fields
| |
Instances
| Show HintRule |
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 values for ParseFlags.
data ParseError Source
A parse error from parseModuleEx.
Constructors
| ParseError | |
Fields
| |
What C pre processor should be used.
Constructors
| NoCpp | No pre processing is done. |
| CppSimple | Lines prefixed with |
| Cpphs CpphsOptions | The |
File encodings
An Encoding represents how characters are stored in a file. Created with
defaultEncoding or readEncoding and used with useEncoding.
defaultEncoding :: EncodingSource
The system default encoding.
readEncoding :: String -> IO EncodingSource
Create an encoding from a string, or throw an error if the encoding is not known.
Accepts many encodings including locale, utf-8 and all those supported by the
GHC mkTextEncoding function.
useEncoding :: Handle -> Encoding -> IO ()Source
Apply an encoding to a Handle.