hlint-1.9.41: Source code suggestions

Safe HaskellNone
LanguageHaskell2010

Language.Haskell.HLint2

Contents

Description

WARNING: This module represents the evolving second version of the HLint API. It will be deleted in favour of Language.Haskell.HLint3 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]

Synopsis

Documentation

applyHints :: [Classify] -> Hint -> [(Module_, [Comment])] -> [Idea] Source #

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

data Idea Source #

An idea suggest by a Hint.

Constructors

Idea 

Fields

Instances

Eq Idea Source # 

Methods

(==) :: Idea -> Idea -> Bool #

(/=) :: Idea -> Idea -> Bool #

Ord Idea Source # 

Methods

compare :: Idea -> Idea -> Ordering #

(<) :: Idea -> Idea -> Bool #

(<=) :: Idea -> Idea -> Bool #

(>) :: Idea -> Idea -> Bool #

(>=) :: Idea -> Idea -> Bool #

max :: Idea -> Idea -> Idea #

min :: Idea -> Idea -> Idea #

Show Idea Source # 

Methods

showsPrec :: Int -> Idea -> ShowS #

show :: Idea -> String #

showList :: [Idea] -> ShowS #

data Severity Source #

How severe an issue is.

Constructors

Ignore

The issue has been explicitly ignored and will usually be hidden (pass --show on the command line to see ignored ideas).

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.

data Note Source #

A note describing the impact of the replacement.

Constructors

IncreasesLaziness

The replacement is increases laziness, for example replacing reverse (reverse x) with x makes the code lazier.

DecreasesLaziness

The replacement is decreases laziness, for example replacing (fst x, snd x) with x makes the code stricter.

RemovesError String

The replacement removes errors, for example replacing foldr1 (+) with sum removes an error on [], and might contain the text "on []".

ValidInstance String String

The replacement assumes standard type class lemmas, a hint with the note ValidInstance "Eq" "x" might only be valid if the x variable has a reflexive Eq instance.

Note String

An arbitrary note.

Instances

Eq Note Source # 

Methods

(==) :: Note -> Note -> Bool #

(/=) :: Note -> Note -> Bool #

Ord Note Source # 

Methods

compare :: Note -> Note -> Ordering #

(<) :: Note -> Note -> Bool #

(<=) :: Note -> Note -> Bool #

(>) :: Note -> Note -> Bool #

(>=) :: Note -> Note -> Bool #

max :: Note -> Note -> Note #

min :: Note -> Note -> Note #

Show Note Source # 

Methods

showsPrec :: Int -> Note -> ShowS #

show :: Note -> String #

showList :: [Note] -> ShowS #

Settings

data Classify Source #

How to classify an Idea. If any matching field is "" then it matches everything.

Constructors

Classify 

Fields

getHLintDataDir :: IO FilePath Source #

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:

  1. Use findSettings to find and load the HLint settings files.
  2. Use readSettings to interpret the settings files, producing HintRule values (LHS ==> RHS replacements) and Classify values to assign Severity ratings to hints.
  3. Use builtinHints and hintRules to generate a Hint value.
  4. Take all fixities from the findSettings modules and put them in the ParseFlags.

autoSettings' :: FilePath -> IO (ParseFlags, [Classify], Hint) Source #

Like autoSettings but with a custom data directory.

findSettings :: FilePath -> FilePath -> Maybe String -> IO ([String], [Module_]) 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:

  1. Builtin hints to use, e.g. List, which should be resolved using builtinHints.
  2. A list of modules containing hints, suitable for processing with readSettings.

Any parse failures will result in an exception.

readSettings :: Module_ -> ([Classify], [HintRule]) Source #

Given a module containing HLint settings information return the Classify rules and the HintRule expressions. Any fixity declarations will be discarded, but any other unrecognised elements will result in an exception.

Hints

data Hint Source #

Functions to generate hints, combined using the Monoid instance.

Constructors

Hint 

Fields

  • hintModules :: [(Scope, Module_)] -> [Idea]

    Given a list of modules (and their scope information) generate some Ideas.

  • hintModule :: Scope -> Module_ -> [Idea]

    Given a single module and its scope information generate some Ideas.

  • hintDecl :: Scope -> Module_ -> Decl_ -> [Idea]

    Given a declaration (with a module and scope) generate some Ideas. This function will be partially applied with one module/scope, then used on multiple Decl values.

  • hintComment :: Comment -> [Idea]

    Given a comment generate some Ideas.

Instances

builtinHints :: [(String, Hint)] Source #

A list of builtin hints, currently including entries such as "List" and "Bracket".

data HintRule Source #

A LHS ==> RHS style hint rule.

Constructors

HintRule 

Fields

hintRules :: [HintRule] -> Hint Source #

Transform a list of HintRule into a Hint.

Scopes

data Scope Source #

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.

Instances

scopeCreate :: Module_ -> Scope Source #

Create a Scope value from a module, based on the modules imports.

scopeMatch :: (Scope, QName S) -> (Scope, QName S) -> Bool Source #

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 Source #

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])) 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.

data ParseError Source #

A parse error from parseModuleEx.

Constructors

ParseError 

Fields

data ParseFlags Source #

Created with defaultParseFlags, used by parseModuleEx.

Constructors

ParseFlags 

Fields

data CppFlags Source #

What C pre processor should be used.

Constructors

NoCpp

No pre processing is done.

CppSimple

Lines prefixed with # are stripped.

Cpphs CpphsOptions

The cpphs library is used.

File encodings

type Encoding = TextEncoding Source #

An Encoding represents how characters are stored in a file. Created with defaultEncoding or readEncoding and used with useEncoding.

defaultEncoding :: Encoding Source #

The system default encoding.

readEncoding :: String -> IO Encoding Source #

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.