Move ProjectRuleSchema's phantom type to be the first type variable

This commit is contained in:
Jeroen Engels 2020-03-24 19:55:03 +01:00
parent 07e211f076
commit 772ca5e423
7 changed files with 40 additions and 40 deletions

View File

@ -8,20 +8,20 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
{ canAddModuleVisitor : (), withModuleContext : Rule.Forbidden }
() ()
moduleContext moduleContext
{ canAddModuleVisitor : (), withModuleContext : Rule.Forbidden }
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
moduleContext
{ a { a
| canAddModuleVisitor : () | canAddModuleVisitor : ()
, hasAtLeastOneVisitor : () , hasAtLeastOneVisitor : ()
, withModuleContext : Rule.Forbidden , withModuleContext : Rule.Forbidden
} }
()
moduleContext
Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be
canAddModuleVisitor? canAddModuleVisitor?

View File

@ -12,14 +12,14 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.Forbidden } { canAddModuleVisitor : (), withModuleContext : Rule.Forbidden }
()
()
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.Required } { canAddModuleVisitor : (), withModuleContext : Rule.Required }
()
()

View File

@ -14,20 +14,20 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ hasAtLeastOneVisitor : (), withModuleContext : Rule.Forbidden } { hasAtLeastOneVisitor : (), withModuleContext : Rule.Forbidden }
()
()
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ a { a
| canAddModuleVisitor : () | canAddModuleVisitor : ()
, hasAtLeastOneVisitor : () , hasAtLeastOneVisitor : ()
, withModuleContext : Rule.Forbidden , withModuleContext : Rule.Forbidden
} }
()
()
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
hasAtLeastOneVisitor? hasAtLeastOneVisitor?

View File

@ -9,20 +9,20 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.Forbidden } { canAddModuleVisitor : (), withModuleContext : Rule.Forbidden }
()
()
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ a { a
| canAddModuleVisitor : () | canAddModuleVisitor : ()
, hasAtLeastOneVisitor : () , hasAtLeastOneVisitor : ()
, withModuleContext : Rule.Forbidden , withModuleContext : Rule.Forbidden
} }
()
()
Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be
canAddModuleVisitor? canAddModuleVisitor?

View File

@ -18,20 +18,20 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ hasAtLeastOneVisitor : (), withModuleContext : Rule.Forbidden } { hasAtLeastOneVisitor : (), withModuleContext : Rule.Forbidden }
()
()
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
()
()
{ a { a
| canAddModuleVisitor : () | canAddModuleVisitor : ()
, hasAtLeastOneVisitor : () , hasAtLeastOneVisitor : ()
, withModuleContext : Rule.Required , withModuleContext : Rule.Required
} }
()
()
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
hasAtLeastOneVisitor? hasAtLeastOneVisitor?

View File

@ -716,7 +716,7 @@ See the documentation for [`newProjectRuleSchema`](#newProjectRuleSchema) for
how to create a project rule. how to create a project rule.
-} -}
type ProjectRuleSchema projectContext moduleContext schemaState type ProjectRuleSchema schemaState projectContext moduleContext
= ProjectRuleSchema = ProjectRuleSchema
{ name : String { name : String
, initialProjectContext : projectContext , initialProjectContext : projectContext
@ -770,7 +770,7 @@ Evaluating/visiting a node means two things:
part of the traversal evaluation. part of the traversal evaluation.
-} -}
newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext { canAddModuleVisitor : (), withModuleContext : Forbidden } newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema { canAddModuleVisitor : (), withModuleContext : Forbidden } projectContext moduleContext
newProjectRuleSchema name_ initialProjectContext = newProjectRuleSchema name_ initialProjectContext =
ProjectRuleSchema ProjectRuleSchema
{ name = name_ { name = name_
@ -786,7 +786,7 @@ newProjectRuleSchema name_ initialProjectContext =
{-| Create a [`Rule`](#Rule) from a configured [`ProjectRuleSchema`](#ProjectRuleSchema). {-| Create a [`Rule`](#Rule) from a configured [`ProjectRuleSchema`](#ProjectRuleSchema).
-} -}
fromProjectRuleSchema : ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : Forbidden, hasAtLeastOneVisitor : () } -> Rule fromProjectRuleSchema : ProjectRuleSchema { schemaState | withModuleContext : Forbidden, hasAtLeastOneVisitor : () } projectContext moduleContext -> Rule
fromProjectRuleSchema (ProjectRuleSchema schema) = fromProjectRuleSchema (ProjectRuleSchema schema) =
Rule schema.name Rule schema.name
Exceptions.init Exceptions.init
@ -820,8 +820,8 @@ in order to specify how to create a `moduleContext` from a `projectContext` and
-} -}
withModuleVisitor : withModuleVisitor :
(ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { moduleSchemaState | hasAtLeastOneVisitor : () } moduleContext) (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { moduleSchemaState | hasAtLeastOneVisitor : () } moduleContext)
-> ProjectRuleSchema projectContext moduleContext { projectSchemaState | canAddModuleVisitor : () } -> ProjectRuleSchema { projectSchemaState | canAddModuleVisitor : () } projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext { projectSchemaState | canAddModuleVisitor : (), withModuleContext : Required } -> ProjectRuleSchema { projectSchemaState | canAddModuleVisitor : (), withModuleContext : Required } projectContext moduleContext
withModuleVisitor visitor (ProjectRuleSchema schema) = withModuleVisitor visitor (ProjectRuleSchema schema) =
let let
previousModuleVisitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) previousModuleVisitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
@ -1098,8 +1098,8 @@ withModuleContext :
, fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext , fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext
, foldProjectContexts : projectContext -> projectContext -> projectContext , foldProjectContexts : projectContext -> projectContext -> projectContext
} }
-> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required } -> ProjectRuleSchema { schemaState | canAddModuleVisitor : (), withModuleContext : Required } projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : (), withModuleContext : Forbidden } -> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : (), withModuleContext : Forbidden } projectContext moduleContext
withModuleContext moduleContext (ProjectRuleSchema schema) = withModuleContext moduleContext (ProjectRuleSchema schema) =
let let
visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
@ -1126,8 +1126,8 @@ The visitor will be called before any module is evaluated.
-} -}
withElmJsonProjectVisitor : withElmJsonProjectVisitor :
(Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List Error, projectContext )) (Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () } -> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withElmJsonProjectVisitor visitor (ProjectRuleSchema schema) = withElmJsonProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors } ProjectRuleSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors }
@ -1141,8 +1141,8 @@ The visitor will be called before any module is evaluated.
-} -}
withReadmeProjectVisitor : withReadmeProjectVisitor :
(Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List Error, projectContext )) (Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () } -> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withReadmeProjectVisitor visitor (ProjectRuleSchema schema) = withReadmeProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | readmeVisitors = visitor :: schema.readmeVisitors } ProjectRuleSchema { schema | readmeVisitors = visitor :: schema.readmeVisitors }
@ -1156,8 +1156,8 @@ module is evaluated.
-} -}
withDependenciesProjectVisitor : withDependenciesProjectVisitor :
(Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List Error, projectContext )) (Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () } -> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withDependenciesProjectVisitor visitor (ProjectRuleSchema schema) = withDependenciesProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | dependenciesVisitors = visitor :: schema.dependenciesVisitors } ProjectRuleSchema { schema | dependenciesVisitors = visitor :: schema.dependenciesVisitors }
@ -1175,8 +1175,8 @@ That means that if you call [`error`](#error), we won't know which module to ass
-} -}
withFinalProjectEvaluation : withFinalProjectEvaluation :
(projectContext -> List Error) (projectContext -> List Error)
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema schemaState projectContext moduleContext
withFinalProjectEvaluation visitor (ProjectRuleSchema schema) = withFinalProjectEvaluation visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | finalEvaluationFns = visitor :: schema.finalEvaluationFns } ProjectRuleSchema { schema | finalEvaluationFns = visitor :: schema.finalEvaluationFns }
@ -1207,7 +1207,7 @@ and the analysis will be much faster, because we know other files won't influenc
the results of other modules' analysis. the results of other modules' analysis.
-} -}
withContextFromImportedModules : ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema projectContext moduleContext schemaState withContextFromImportedModules : ProjectRuleSchema schemaState projectContext moduleContext -> ProjectRuleSchema schemaState projectContext moduleContext
withContextFromImportedModules (ProjectRuleSchema schema) = withContextFromImportedModules (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | traversalType = ImportedModulesFirst } ProjectRuleSchema { schema | traversalType = ImportedModulesFirst }
@ -1220,7 +1220,7 @@ type alias ProjectRuleCache projectContext =
} }
runProjectRule : ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleCache projectContext -> Exceptions -> Project -> List (Graph.NodeContext ModuleName ()) -> ( List Error, Rule ) runProjectRule : ProjectRuleSchema schemaState projectContext moduleContext -> ProjectRuleCache projectContext -> Exceptions -> Project -> List (Graph.NodeContext ModuleName ()) -> ( List Error, Rule )
runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache exceptions project nodeContexts = runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache exceptions project nodeContexts =
let let
elmJsonData : Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } elmJsonData : Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project }
@ -1295,7 +1295,7 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache exceptio
computeModules : computeModules :
ProjectRuleSchema projectContext moduleContext schemaState ProjectRuleSchema schemaState projectContext moduleContext
-> ->
{ visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) { visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
, moduleContext : ModuleContextFunctions projectContext moduleContext , moduleContext : ModuleContextFunctions projectContext moduleContext
@ -1518,7 +1518,7 @@ getModuleName module_ =
|> Module.moduleName |> Module.moduleName
errorsFromFinalEvaluationForProject : ProjectRuleSchema projectContext moduleContext schemaState -> projectContext -> List projectContext -> List Error errorsFromFinalEvaluationForProject : ProjectRuleSchema schemaState projectContext moduleContext -> projectContext -> List projectContext -> List Error
errorsFromFinalEvaluationForProject (ProjectRuleSchema schema) initialContext contextsPerModule = errorsFromFinalEvaluationForProject (ProjectRuleSchema schema) initialContext contextsPerModule =
if List.isEmpty schema.finalEvaluationFns then if List.isEmpty schema.finalEvaluationFns then
[] []

View File

@ -167,8 +167,8 @@ emptyScope =
addProjectVisitors : addProjectVisitors :
Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } { schemaState | canAddModuleVisitor : () } Rule.ProjectRuleSchema { schemaState | canAddModuleVisitor : () } { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext }
-> Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } { schemaState | canAddModuleVisitor : (), hasAtLeastOneVisitor : (), withModuleContext : Rule.Required } -> Rule.ProjectRuleSchema { schemaState | canAddModuleVisitor : (), hasAtLeastOneVisitor : (), withModuleContext : Rule.Required } { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext }
addProjectVisitors schema = addProjectVisitors schema =
schema schema
|> Rule.withContextFromImportedModules |> Rule.withContextFromImportedModules