Changed rule signature to be able to make a list of rules

This commit is contained in:
Jeroen Engels 2017-01-15 23:24:37 +01:00
parent c6ab2b4b8a
commit c52c169572
6 changed files with 47 additions and 23 deletions

View File

@ -19,7 +19,7 @@ visitAndAccumulate rule visitor ( errors, ctx ) =
lintWithVisitors : List (Visitor context) -> LintRule context -> List Error
lintWithVisitors visitors rule =
visitors
|> List.foldl (visitAndAccumulate rule) ( [], rule.context )
|> List.foldl (visitAndAccumulate rule) ( [], rule.initialContext )
|> Tuple.first

View File

@ -22,7 +22,7 @@ type alias LintRule context =
, typeFn : LintImplementation Type context
, expressionFn : LintImplementation Expression context
, moduleEndFn : context -> ( List Error, context )
, context : context
, initialContext : context
}

View File

@ -9,6 +9,7 @@ import Html.Attributes exposing (id, class)
import Html.Events exposing (..)
import Json.Decode as JD
import Lint
import Types
-- Rules
@ -97,20 +98,28 @@ tree ast =
div [] [ text <| toString err ]
rules : List (String -> List Types.Error)
rules =
[ FindNoAnnotatedFunction.rule
, NoDebug.rule
, NoExposingEverything.rule
]
lint : String -> Html Msg
lint source =
let
lint =
Lint.lint source
errors =
List.concat
[ lint FindNoAnnotatedFunction.rule
, lint NoDebug.rule
, lint NoExposingEverything.rule
]
List.map (\rule -> rule source) rules
|> List.concat
in
div [] (List.map (\x -> p [] [ text x ]) errors)
div []
(List.map
(\x ->
p [] [ text x ]
)
errors
)
view : String -> Html Msg

View File

@ -1,6 +1,6 @@
module FindNoAnnotatedFunction exposing (rule)
import Lint exposing (doNothing)
import Lint exposing (lint, doNothing)
import Types exposing (LintRule, Error, Direction(..))
import Ast.Statement exposing (..)
import Set exposing (Set)
@ -11,13 +11,18 @@ type alias Context =
}
rule : LintRule Context
rule =
rule : String -> List Error
rule input =
lint input implementation
implementation : LintRule Context
implementation =
{ statementFn = statementFn
, typeFn = doNothing
, expressionFn = doNothing
, moduleEndFn = (\ctx -> ( [], ctx ))
, context = Context Set.empty
, initialContext = Context Set.empty
}

View File

@ -1,6 +1,6 @@
module NoDebug exposing (rule)
import Lint exposing (doNothing)
import Lint exposing (lint, doNothing)
import Types exposing (LintRule, Error, Direction(..))
import Ast.Expression exposing (..)
@ -9,13 +9,18 @@ type alias Context =
{}
rule : LintRule Context
rule =
rule : String -> List Error
rule input =
lint input implementation
implementation : LintRule Context
implementation =
{ statementFn = doNothing
, typeFn = doNothing
, expressionFn = expressionFn
, moduleEndFn = (\ctx -> ( [], ctx ))
, context = Context
, initialContext = Context
}

View File

@ -1,6 +1,6 @@
module NoExposingEverything exposing (rule)
import Lint exposing (doNothing)
import Lint exposing (lint, doNothing)
import Types exposing (LintRule, Error, Direction(..))
import Ast.Statement exposing (..)
@ -9,13 +9,18 @@ type alias Context =
{}
rule : LintRule Context
rule =
rule : String -> List Error
rule input =
lint input implementation
implementation : LintRule Context
implementation =
{ statementFn = statementFn
, typeFn = doNothing
, expressionFn = doNothing
, moduleEndFn = (\ctx -> ( [], ctx ))
, context = Context
, initialContext = Context
}