Make it impossible to have a project rule without visitors

This commit is contained in:
Jeroen Engels 2020-03-20 20:53:09 +01:00
parent 71f945de5f
commit ae27c82ce6
8 changed files with 81 additions and 14 deletions

View File

@ -0,0 +1,12 @@
module No_Project_Rule_Without_Visitors exposing (rule)
{-| We want to forbid having project rules without any visitors.
-}
import Review.Rule as Rule exposing (Rule)
rule : Rule
rule =
Rule.newProjectRuleSchema "No_Project_Rule_Without_Visitors" ()
|> Rule.fromProjectRuleSchema

View File

@ -0,0 +1,31 @@
-- TYPE MISMATCH ------------------------ ./No_Project_Rule_Without_Visitors.elm
This function cannot handle the argument sent through the (|>) pipe:
11| Rule.newProjectRuleSchema "No_Project_Rule_Without_Visitors" ()
12| |> Rule.fromProjectRuleSchema
^^^^^^^^^^^^^^^^^^^^^^^^^^
The argument is:
Rule.ProjectRuleSchema
()
moduleContext
{ canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
moduleContext
{ a
| canAddModuleVisitor : ()
, hasAtLeastOneVisitor : ()
, withModuleContext : Rule.NotNeeded
}
Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be
canAddModuleVisitor?
Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!

View File

@ -13,17 +13,24 @@ This function cannot handle the argument sent through the (|>) pipe:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The argument is:
Rule.ProjectRuleSchema () () { withModuleContext : Rule.NotNeeded }
Rule.ProjectRuleSchema
()
()
{ hasAtLeastOneVisitor : (), withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ a | canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
{ a
| canAddModuleVisitor : ()
, hasAtLeastOneVisitor : ()
, withModuleContext : Rule.NotNeeded
}
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
withModuleContext?
hasAtLeastOneVisitor?
Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!

View File

@ -18,5 +18,15 @@ But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
{ a
| canAddModuleVisitor : ()
, hasAtLeastOneVisitor : ()
, withModuleContext : Rule.NotNeeded
}
Hint: Seems like a record field typo. Maybe hasAtLeastOneVisitor should be
canAddModuleVisitor?
Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!

View File

@ -17,19 +17,24 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is:
Rule.ProjectRuleSchema () () { withModuleContext : Rule.NotNeeded }
Rule.ProjectRuleSchema
()
()
{ hasAtLeastOneVisitor : (), withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ schemaState
| canAddModuleVisitor : (), withModuleContext : Rule.Required
{ a
| canAddModuleVisitor : ()
, hasAtLeastOneVisitor : ()
, withModuleContext : Rule.Required
}
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
withModuleContext?
hasAtLeastOneVisitor?
Hint: Can more type annotations be added? Type annotations always help me give
more specific messages, and I think they could help a lot in this case!

View File

@ -21,3 +21,5 @@ elmFiles.forEach(elmFile => {
}
}
});
console.log('No problems with phantom types!');

View File

@ -947,7 +947,7 @@ newProjectRuleSchema name_ initialProjectContext =
{-| Create a [`Rule`](#Rule) from a configured [`ProjectRuleSchema`](#ProjectRuleSchema).
-}
fromProjectRuleSchema : ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : NotNeeded } -> Rule
fromProjectRuleSchema : ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : NotNeeded, hasAtLeastOneVisitor : () } -> Rule
fromProjectRuleSchema (ProjectRuleSchema schema) =
Rule schema.name
Exceptions.init
@ -1007,7 +1007,7 @@ withModuleContext :
, foldProjectContexts : projectContext -> projectContext -> projectContext
}
-> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required }
-> ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : NotNeeded }
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : (), withModuleContext : NotNeeded }
withModuleContext moduleContext (ProjectRuleSchema schema) =
let
visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
@ -1035,7 +1035,7 @@ module is evaluated.
withElmJsonProjectVisitor :
(Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () }
withElmJsonProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors }
@ -1051,7 +1051,7 @@ module is evaluated.
withReadmeProjectVisitor :
(Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () }
withReadmeProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | readmeVisitors = visitor :: schema.readmeVisitors }
@ -1066,7 +1066,7 @@ module is evaluated.
withDependenciesProjectVisitor :
(Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List Error, projectContext ))
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext { schemaState | hasAtLeastOneVisitor : () }
withDependenciesProjectVisitor visitor (ProjectRuleSchema schema) =
ProjectRuleSchema { schema | dependenciesVisitors = visitor :: schema.dependenciesVisitors }

View File

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