Prevent use of error in project visitors

This commit is contained in:
Jeroen Engels 2020-03-25 18:35:23 +01:00
parent 31cd0c6691
commit 5dec76b06c
6 changed files with 27 additions and 20 deletions

View File

@ -121,7 +121,7 @@ initialProjectContext =
-- FINAL EVALUATION
finalEvaluationForProject : Configuration -> ProjectContext -> List (Error {})
finalEvaluationForProject : Configuration -> ProjectContext -> List (Error { useErrorForModule : () })
finalEvaluationForProject configuration projectContext =
case projectContext.elmJsonKey of
Just elmJsonKey ->

View File

@ -451,7 +451,7 @@ isCapitalized name =
-- FINAL PROJECT EVALUATION
finalProjectEvaluation : ProjectContext -> List (Error {})
finalProjectEvaluation : ProjectContext -> List (Error { useErrorForModule : () })
finalProjectEvaluation projectContext =
projectContext.exposedConstructors
|> Dict.toList

View File

@ -187,7 +187,7 @@ moduleNameForImport node =
-- FINAL EVALUATION
finalEvaluationForProject : ProjectContext -> List (Error {})
finalEvaluationForProject : ProjectContext -> List (Error { useErrorForModule : () })
finalEvaluationForProject projectContext =
case projectContext.elmJsonKey of
Just elmJsonKey ->
@ -203,7 +203,7 @@ finalEvaluationForProject projectContext =
[]
error : Rule.ElmJsonKey -> String -> Error {}
error : Rule.ElmJsonKey -> String -> Error scope
error elmJsonKey packageName =
Rule.errorForElmJson elmJsonKey
(\elmJson ->

View File

@ -202,7 +202,7 @@ elmJsonVisitor maybeProject projectContext =
-- PROJECT EVALUATION
finalEvaluationForProject : ProjectContext -> List (Error {})
finalEvaluationForProject : ProjectContext -> List (Error { useErrorForModule : () })
finalEvaluationForProject projectContext =
projectContext.modules
|> removeExposedPackages projectContext
@ -229,12 +229,7 @@ finalEvaluationForProject projectContext =
ExposedType ->
"Exposed type"
in
[ Rule.error
{ message = what ++ " `" ++ name ++ "` is never used outside this module."
, details = [ "This exposed element is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project." ]
}
range
, Rule.errorForModule moduleKey
[ Rule.errorForModule moduleKey
{ message = what ++ " `" ++ name ++ "` is never used outside this module."
, details = [ "This exposed element is never used. You may want to remove it to keep your project clean, and maybe detect some unused code in your project." ]
}

View File

@ -1129,11 +1129,11 @@ The visitor will be called before any module is evaluated.
-}
withElmJsonProjectVisitor :
(Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List (Error {}), projectContext ))
(Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List (Error { useErrorForModule : () }), projectContext ))
-> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withElmJsonProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors }
ProjectRuleSchema { schema | elmJsonVisitors = removeErrorPhantomTypeFromVisitor visitor :: schema.elmJsonVisitors }
{-| Add a visitor to the [`ProjectRuleSchema`](#ProjectRuleSchema) which will visit
@ -1144,11 +1144,11 @@ The visitor will be called before any module is evaluated.
-}
withReadmeProjectVisitor :
(Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List (Error {}), projectContext ))
(Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List (Error { useErrorForModule : () }), projectContext ))
-> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withReadmeProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | readmeVisitors = visitor :: schema.readmeVisitors }
ProjectRuleSchema { schema | readmeVisitors = removeErrorPhantomTypeFromVisitor visitor :: schema.readmeVisitors }
{-| Add a visitor to the [`ProjectRuleSchema`](#ProjectRuleSchema) which will visit the project's
@ -1159,11 +1159,11 @@ module is evaluated.
-}
withDependenciesProjectVisitor :
(Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List (Error {}), projectContext ))
(Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List (Error { useErrorForModule : () }), projectContext ))
-> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withDependenciesProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | dependenciesVisitors = visitor :: schema.dependenciesVisitors }
ProjectRuleSchema { schema | dependenciesVisitors = removeErrorPhantomTypeFromVisitor visitor :: schema.dependenciesVisitors }
{-| Add a function that makes a final evaluation of the project based only on the
@ -1178,11 +1178,23 @@ That means that if you call [`error`](#error), we won't know which module to ass
-}
withFinalProjectEvaluation :
(projectContext -> List (Error {}))
(projectContext -> List (Error { useErrorForModule : () }))
-> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema schemaState projectContext moduleContext
withFinalProjectEvaluation visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | finalEvaluationFns = visitor :: schema.finalEvaluationFns }
let
removeErrorPhantomTypeFromEvaluation : (projectContext -> List (Error b)) -> (projectContext -> List (Error {}))
removeErrorPhantomTypeFromEvaluation function projectContext =
function projectContext
|> List.map removeErrorPhantomType
in
ProjectRuleSchema { schema | finalEvaluationFns = removeErrorPhantomTypeFromEvaluation visitor :: schema.finalEvaluationFns }
removeErrorPhantomTypeFromVisitor : (element -> projectContext -> ( List (Error b), projectContext )) -> (element -> projectContext -> ( List (Error {}), projectContext ))
removeErrorPhantomTypeFromVisitor function element projectContext =
function element projectContext
|> Tuple.mapFirst (List.map removeErrorPhantomType)
{-| Allows the rule to have access to the context of the modules imported by the

View File

@ -26,7 +26,7 @@ initialProjectContext =
Nothing
finalEvaluationForProject : Context -> List (Error {})
finalEvaluationForProject : Context -> List (Error { useErrorForModule : () })
finalEvaluationForProject maybeElmJsonKey =
case maybeElmJsonKey of
Just elmJsonKey ->