A linter for Elm.
See Lint.Rules for available rules. To define the rules you wish to use:
rules =
[ Lint.Rules.NoDebug.rule
, Lint.Rules.NoUnusedVariables
]To run the rules on a source code and get a list of errors:
lint : String -> List String
lint source =
let
errors =
List.concatMap (\rule -> rule source) rules
in
if List.isEmpty errors then
[ "No errors." ]
else
List.map (\err -> err.rule ++ ": " ++ err.message) errorsLints source code using a given rule implementation, and gives back a list of errors that were found.
rule : LintRule
rule input =
lint input implementation
implementation : LintRuleImplementation Context
implementation =
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = expressionFn
, moduleEndFn = (\ctx -> ( [], ctx ))
, initialContext = Context
}Basic implementation of a visitor function that does nothing, i.e. return an empty list of errors and an untouched context. This is used to avoid a bit of boilerplate for visitor functions whose node types we are not interested in.
implementation : LintRuleImplementation Context
implementation =
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = expressionFn
, moduleEndFn = (\ctx -> ( [], ctx ))
, initialContext = Context
}Visit an expression using a sub rule implementation. The use of this function is not encouraged, but it can make part of the implementation of complex rules much easier. It gives back a list of errors and a context.
expressionFn : Context -> Direction Expression -> ( List LintError, Context )
expressionFn ctx node =
case node of
Enter (Case expr patterns) ->
visitExpression subimplementation expr
_ ->
( [], ctx )
subimplementation : LintRuleImplementation Subcontext
subimplementation =
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = subexpressionFn
, moduleEndFn = (\ctx -> ( [], ctx ))
, initialContext = Subcontext
}Count the number of errors of a given Severity in the list of errors.
Parse source code into a AST
Lints a file and gives back the errors raised by the given rules.