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 : List (Visitor context) -> LintRule context -> List Error
lintWithVisitors visitors rule = lintWithVisitors visitors rule =
visitors visitors
|> List.foldl (visitAndAccumulate rule) ( [], rule.context ) |> List.foldl (visitAndAccumulate rule) ( [], rule.initialContext )
|> Tuple.first |> Tuple.first

View File

@ -22,7 +22,7 @@ type alias LintRule context =
, typeFn : LintImplementation Type context , typeFn : LintImplementation Type context
, expressionFn : LintImplementation Expression context , expressionFn : LintImplementation Expression context
, moduleEndFn : context -> ( List Error, 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 Html.Events exposing (..)
import Json.Decode as JD import Json.Decode as JD
import Lint import Lint
import Types
-- Rules -- Rules
@ -97,20 +98,28 @@ tree ast =
div [] [ text <| toString err ] div [] [ text <| toString err ]
rules : List (String -> List Types.Error)
rules =
[ FindNoAnnotatedFunction.rule
, NoDebug.rule
, NoExposingEverything.rule
]
lint : String -> Html Msg lint : String -> Html Msg
lint source = lint source =
let let
lint =
Lint.lint source
errors = errors =
List.concat List.map (\rule -> rule source) rules
[ lint FindNoAnnotatedFunction.rule |> List.concat
, lint NoDebug.rule
, lint NoExposingEverything.rule
]
in in
div [] (List.map (\x -> p [] [ text x ]) errors) div []
(List.map
(\x ->
p [] [ text x ]
)
errors
)
view : String -> Html Msg view : String -> Html Msg

View File

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

View File

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

View File

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