mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-28 09:02:53 +03:00
Add FindNoAnnotatedFunction rule
This commit is contained in:
parent
a0e532c07b
commit
3c27a18207
47
Lint.elm
47
Lint.elm
@ -29,28 +29,28 @@ doNothing ctx _ =
|
|||||||
( [], ctx )
|
( [], ctx )
|
||||||
|
|
||||||
|
|
||||||
visitExpression : Expression -> Visitor context
|
expressionVisitor : Expression -> Visitor context
|
||||||
visitExpression node rule context =
|
expressionVisitor node rule context =
|
||||||
rule.expressionFn context node
|
rule.expressionFn context node
|
||||||
|
|
||||||
|
|
||||||
visitType : Type -> Visitor context
|
typeVisitor : Type -> Visitor context
|
||||||
visitType node rule context =
|
typeVisitor node rule context =
|
||||||
rule.typeFn context node
|
rule.typeFn context node
|
||||||
|
|
||||||
|
|
||||||
visitStatement : Statement -> Visitor context
|
statementVisitor : Statement -> Visitor context
|
||||||
visitStatement node rule context =
|
statementVisitor node rule context =
|
||||||
rule.statementFn context node
|
rule.statementFn context node
|
||||||
|
|
||||||
|
|
||||||
transformExpression : Expression -> List (Visitor context)
|
expressionToVisitors : Expression -> List (Visitor context)
|
||||||
transformExpression node =
|
expressionToVisitors node =
|
||||||
let
|
let
|
||||||
visitAndTransformChildren children =
|
visitAndTransformChildren children =
|
||||||
List.concat
|
List.concat
|
||||||
[ [ visitExpression node ]
|
[ [ expressionVisitor node ]
|
||||||
, List.concatMap transformExpression children
|
, List.concatMap expressionToVisitors children
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
case node of
|
case node of
|
||||||
@ -61,25 +61,25 @@ transformExpression node =
|
|||||||
visitAndTransformChildren [ expression ]
|
visitAndTransformChildren [ expression ]
|
||||||
|
|
||||||
Variable _ ->
|
Variable _ ->
|
||||||
[ visitExpression node ]
|
[ expressionVisitor node ]
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
transformType : Type -> List (Visitor context)
|
typeToVisitors : Type -> List (Visitor context)
|
||||||
transformType node =
|
typeToVisitors node =
|
||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
transformStatement : Statement -> List (Visitor context)
|
statementToVisitors : Statement -> List (Visitor context)
|
||||||
transformStatement node =
|
statementToVisitors node =
|
||||||
let
|
let
|
||||||
visitAndTransformChildren expresssions types =
|
visitAndTransformChildren expresssions types =
|
||||||
List.concat
|
List.concat
|
||||||
[ [ visitStatement node ]
|
[ [ statementVisitor node ]
|
||||||
, List.concatMap transformExpression expresssions
|
, List.concatMap expressionToVisitors expresssions
|
||||||
, List.concatMap transformType types
|
, List.concatMap typeToVisitors types
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
case node of
|
case node of
|
||||||
@ -93,16 +93,11 @@ transformStatement node =
|
|||||||
[]
|
[]
|
||||||
|
|
||||||
|
|
||||||
transform : List Statement -> List (Visitor context)
|
|
||||||
transform statements =
|
|
||||||
List.concatMap transformStatement statements
|
|
||||||
|
|
||||||
|
|
||||||
lint : List Statement -> LintRule context -> List Error
|
lint : List Statement -> LintRule context -> List Error
|
||||||
lint statements rule =
|
lint statements rule =
|
||||||
let
|
let
|
||||||
validators =
|
visitors =
|
||||||
transform statements
|
List.concatMap statementToVisitors statements
|
||||||
|
|
||||||
( errors, _ ) =
|
( errors, _ ) =
|
||||||
List.foldl
|
List.foldl
|
||||||
@ -114,6 +109,6 @@ lint statements rule =
|
|||||||
( errors ++ errors_, ctx_ )
|
( errors ++ errors_, ctx_ )
|
||||||
)
|
)
|
||||||
( [], rule.context )
|
( [], rule.context )
|
||||||
validators
|
visitors
|
||||||
in
|
in
|
||||||
errors
|
errors
|
||||||
|
@ -10,6 +10,7 @@ import Html.Events exposing (..)
|
|||||||
import Json.Decode as JD
|
import Json.Decode as JD
|
||||||
import Lint
|
import Lint
|
||||||
import NoDebug
|
import NoDebug
|
||||||
|
import FindNoAnnotatedFunction
|
||||||
|
|
||||||
|
|
||||||
type Msg
|
type Msg
|
||||||
@ -100,7 +101,10 @@ lint ast =
|
|||||||
|> Result.withDefault []
|
|> Result.withDefault []
|
||||||
|
|
||||||
errors =
|
errors =
|
||||||
Lint.lint statements NoDebug.rule
|
List.concat
|
||||||
|
[ Lint.lint statements FindNoAnnotatedFunction.rule
|
||||||
|
, Lint.lint statements NoDebug.rule
|
||||||
|
]
|
||||||
in
|
in
|
||||||
div [] (List.map (\x -> p [] [ text x ]) errors)
|
div [] (List.map (\x -> p [] [ text x ]) errors)
|
||||||
|
|
||||||
|
34
rules/FindNoAnnotatedFunction.elm
Normal file
34
rules/FindNoAnnotatedFunction.elm
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
module FindNoAnnotatedFunction exposing (rule)
|
||||||
|
|
||||||
|
import Lint exposing (LintRule, Error, doNothing)
|
||||||
|
import Ast.Statement exposing (..)
|
||||||
|
|
||||||
|
|
||||||
|
type alias Context =
|
||||||
|
{ annotatedFunctions : List String
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rule : LintRule Context
|
||||||
|
rule =
|
||||||
|
{ statementFn = statementFn
|
||||||
|
, typeFn = doNothing
|
||||||
|
, expressionFn = doNothing
|
||||||
|
, context = Context []
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
statementFn : Context -> Statement -> ( List Error, Context )
|
||||||
|
statementFn ctx node =
|
||||||
|
case node of
|
||||||
|
FunctionTypeDeclaration name application ->
|
||||||
|
( [], { ctx | annotatedFunctions = name :: ctx.annotatedFunctions } )
|
||||||
|
|
||||||
|
FunctionDeclaration name params body ->
|
||||||
|
if List.member name ctx.annotatedFunctions then
|
||||||
|
( [], ctx )
|
||||||
|
else
|
||||||
|
( [ "`" ++ name ++ "` does not have a type declaration" ], ctx )
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
( [], ctx )
|
Loading…
Reference in New Issue
Block a user