Add builder function to add an elm.json visitor for multi rules

This commit is contained in:
Jeroen Engels 2020-01-01 23:11:41 +01:00
parent a63e7afb83
commit 3fec3aa1d2
2 changed files with 16 additions and 6 deletions

View File

@ -47,8 +47,7 @@ unused modules in your application or package.
rule : Rule
rule =
Rule.newMultiSchema "NoUnused.Modules"
{ elmJsonVisitors = [ elmJsonVisitor ]
, dependenciesVisitors = []
{ dependenciesVisitors = []
, moduleVisitorSchema = moduleVisitorSchema
, context =
{ initGlobalContext = initGlobalContext
@ -58,6 +57,7 @@ rule =
}
, finalEvaluation = finalEvaluationForProject
}
|> Rule.withMultiElmJsonVisitor elmJsonVisitor
|> Rule.fromMultiSchema

View File

@ -10,6 +10,7 @@ module Review.Rule exposing
, newMultiSchema, fromMultiSchema, newFileVisitorSchema
, FileKey, errorForFile
, ReviewResult(..)
, withMultiElmJsonVisitor
)
{-| This module contains functions that are used for writing rules.
@ -549,8 +550,7 @@ type MultiSchema globalContext moduleContext
newMultiSchema :
String
->
{ elmJsonVisitors : List (Maybe Elm.Project.Project -> globalContext -> globalContext)
, dependenciesVisitors : List (Dict String Elm.Docs.Module -> globalContext -> globalContext)
{ dependenciesVisitors : List (Dict String Elm.Docs.Module -> globalContext -> globalContext)
, moduleVisitorSchema : Schema ForLookingAtSeveralFiles { hasNoVisitor : () } moduleContext -> Schema ForLookingAtSeveralFiles { hasAtLeastOneVisitor : () } moduleContext
, context :
{ initGlobalContext : globalContext
@ -561,11 +561,11 @@ newMultiSchema :
, finalEvaluation : globalContext -> List Error
}
-> MultiSchema globalContext moduleContext
newMultiSchema name_ { context, elmJsonVisitors, dependenciesVisitors, moduleVisitorSchema, finalEvaluation } =
newMultiSchema name_ { context, dependenciesVisitors, moduleVisitorSchema, finalEvaluation } =
MultiSchema
{ name = name_
, context = context
, elmJsonVisitors = elmJsonVisitors
, elmJsonVisitors = []
, dependenciesVisitors = dependenciesVisitors
, moduleVisitorSchema = moduleVisitorSchema
, finalEvaluationFn = finalEvaluation
@ -718,6 +718,16 @@ moduleNameNode node =
data.moduleName
{-| TODO documentation
-}
withMultiElmJsonVisitor :
(Maybe Elm.Project.Project -> globalContext -> globalContext)
-> MultiSchema globalContext moduleContext
-> MultiSchema globalContext moduleContext
withMultiElmJsonVisitor visitor (MultiSchema schema) =
MultiSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors }
{-| Concatenate the errors of the previous step and of the last step.
-}
makeFinalEvaluation : List (context -> List Error) -> ( List Error, context ) -> List Error