Require calling withModuleContext after withModuleVisitor

This commit is contained in:
Jeroen Engels 2020-03-19 23:26:47 +01:00
parent abac9224bc
commit a2037ea973
6 changed files with 94 additions and 17 deletions

View File

@ -11,18 +11,15 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is:
Rule.ProjectRuleSchema () () { canAddModuleVisitor : () }
Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ a | canAddModuleVisitor : (), withModuleContext : Rule.Required }
Hint: Seems like a record field typo. Maybe withModuleContext 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!
{ canAddModuleVisitor : (), withModuleContext : Rule.Required }

View File

@ -0,0 +1,30 @@
-- TYPE MISMATCH ------------ ./No_WithModuleVisitor_After_WithModuleContext.elm
This function cannot handle the argument sent through the (|>) pipe:
11| Rule.newProjectRuleSchema "No_WithModuleVisitor_After_WithModuleContext" ()
12| |> Rule.withModuleVisitor moduleVisitor
13| |> Rule.withModuleContext
14| { fromProjectToModule = \_ _ () -> ()
15| , fromModuleToProject = \_ _ () -> ()
16| , foldProjectContexts = \_ () -> ()
17| }
18| |> Rule.withModuleVisitor moduleVisitor
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The argument is:
Rule.ProjectRuleSchema () () { withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ a | canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
withModuleContext?
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

@ -0,0 +1,20 @@
module No_WithModuleVisitor_Without_WithModuleContext exposing (rule)
{-| We want to require calling `Rule.withModuleContext` after using `withModuleVisitor`.
-}
import Review.Rule as Rule exposing (Rule)
rule : Rule
rule =
Rule.newProjectRuleSchema "No_WithModuleVisitor_Without_WithModuleContext" ()
|> Rule.withModuleVisitor moduleVisitor
|> Rule.fromProjectRuleSchema
moduleVisitor : Rule.ModuleRuleSchema {} () -> Rule.ModuleRuleSchema { hasAtLeastOneVisitor : () } ()
moduleVisitor schema =
schema
|> Rule.withModuleDefinitionVisitor (\_ () -> ( [], () ))

View File

@ -0,0 +1,22 @@
-- TYPE MISMATCH ---------- ./No_WithModuleVisitor_Without_WithModuleContext.elm
This function cannot handle the argument sent through the (|>) pipe:
11| Rule.newProjectRuleSchema "No_WithModuleVisitor_Without_WithModuleContext" ()
12| |> Rule.withModuleVisitor moduleVisitor
13| |> Rule.fromProjectRuleSchema
^^^^^^^^^^^^^^^^^^^^^^^^^^
The argument is:
Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ canAddModuleVisitor : (), withModuleContext : Rule.NotNeeded }

View File

@ -17,17 +17,19 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is:
Rule.ProjectRuleSchema () () { canAddModuleVisitor : () }
Rule.ProjectRuleSchema () () { withModuleContext : Rule.NotNeeded }
But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema
()
()
{ a | canAddModuleVisitor : (), withModuleContext : Rule.Required }
{ schemaState
| canAddModuleVisitor : (), withModuleContext : Rule.Required
}
Hint: Seems like a record field typo. Maybe withModuleContext should be
canAddModuleVisitor?
Hint: Seems like a record field typo. Maybe canAddModuleVisitor should be
withModuleContext?
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

@ -6,7 +6,7 @@ module Review.Rule exposing
, withModuleDefinitionVisitor, withCommentsVisitor, withImportVisitor, Direction(..), withDeclarationVisitor, withDeclarationListVisitor, withExpressionVisitor, withFinalModuleEvaluation
, withElmJsonModuleVisitor, withReadmeModuleVisitor, withDependenciesModuleVisitor
, ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withContextFromImportedModules
, Required
, Required, NotNeeded
, Error, error, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath, ModuleKey, errorForModule, ElmJsonKey, errorForElmJson, ReadmeKey, errorForReadme
, withFixes
, ignoreErrorsForDirectories, ignoreErrorsForFiles
@ -192,7 +192,7 @@ Evaluating/visiting a node means two things:
## Creating a project rule
@docs ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withContextFromImportedModules
@docs Required
@docs Required, NotNeeded
## Errors
@ -925,7 +925,7 @@ You can't use [`withElmJsonModuleVisitor`](#withElmJsonModuleVisitor) or [`withD
in project rules. Instead, you should use [`withElmJsonProjectVisitor`](#withElmJsonProjectVisitor) or [`withDependenciesProjectVisitor`](#withDependenciesProjectVisitor).
-}
newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext { canAddModuleVisitor : () }
newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext { canAddModuleVisitor : (), withModuleContext : NotNeeded }
newProjectRuleSchema name_ initialProjectContext =
ProjectRuleSchema
{ name = name_
@ -941,7 +941,7 @@ newProjectRuleSchema name_ initialProjectContext =
{-| Create a [`Rule`](#Rule) from a configured [`ProjectRuleSchema`](#ProjectRuleSchema).
-}
fromProjectRuleSchema : ProjectRuleSchema projectContext moduleContext schemaState -> Rule
fromProjectRuleSchema : ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : NotNeeded } -> Rule
fromProjectRuleSchema (ProjectRuleSchema schema) =
Rule schema.name
Exceptions.init
@ -987,6 +987,12 @@ type Required
= Required
{-| TODO Documentation
-}
type NotNeeded
= NotNeeded
{-| TODO Documentation
-}
withModuleContext :
@ -995,7 +1001,7 @@ withModuleContext :
, foldProjectContexts : projectContext -> projectContext -> projectContext
}
-> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required }
-> ProjectRuleSchema projectContext moduleContext schemaState
-> ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : NotNeeded }
withModuleContext moduleContext (ProjectRuleSchema schema) =
let
visitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)