mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-24 07:33:38 +03:00
Changed rule signature to be able to make a list of rules
This commit is contained in:
parent
c6ab2b4b8a
commit
c52c169572
2
Lint.elm
2
Lint.elm
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user