Make it not possible to use withModuleVisitor after withModuleContext

This commit is contained in:
Jeroen Engels 2020-03-19 23:15:42 +01:00
parent 06da24e1aa
commit abac9224bc
6 changed files with 48 additions and 10 deletions

View File

@ -11,12 +11,18 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema () () {} Rule.ProjectRuleSchema () () { canAddModuleVisitor : () }
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
() ()
() ()
{ schemaState | withModuleContext : Rule.Required } { 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!

View File

@ -0,0 +1,26 @@
module No_WithModuleVisitor_After_WithModuleContext exposing (rule)
{-| We want to forbid using `Rule.withModuleVisitor` after having used `withModuleContext`.
-}
import Review.Rule as Rule exposing (Rule)
rule : Rule
rule =
Rule.newProjectRuleSchema "No_WithModuleVisitor_After_WithModuleContext" ()
|> Rule.withModuleVisitor moduleVisitor
|> Rule.withModuleContext
{ fromProjectToModule = \_ _ () -> ()
, fromModuleToProject = \_ _ () -> ()
, foldProjectContexts = \_ () -> ()
}
|> Rule.withModuleVisitor moduleVisitor
|> Rule.withFinalProjectEvaluation (\_ -> [])
|> Rule.fromProjectRuleSchema
moduleVisitor : Rule.ModuleRuleSchema {} () -> Rule.ModuleRuleSchema { hasAtLeastOneVisitor : () } ()
moduleVisitor schema =
schema
|> Rule.withModuleDefinitionVisitor (\_ () -> ( [], () ))

View File

@ -17,12 +17,18 @@ This function cannot handle the argument sent through the (|>) pipe:
The argument is: The argument is:
Rule.ProjectRuleSchema () () {} Rule.ProjectRuleSchema () () { canAddModuleVisitor : () }
But (|>) is piping it to a function that expects: But (|>) is piping it to a function that expects:
Rule.ProjectRuleSchema Rule.ProjectRuleSchema
() ()
() ()
{ schemaState | withModuleContext : Rule.Required } { 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!

View File

@ -925,7 +925,7 @@ You can't use [`withElmJsonModuleVisitor`](#withElmJsonModuleVisitor) or [`withD
in project rules. Instead, you should use [`withElmJsonProjectVisitor`](#withElmJsonProjectVisitor) or [`withDependenciesProjectVisitor`](#withDependenciesProjectVisitor). in project rules. Instead, you should use [`withElmJsonProjectVisitor`](#withElmJsonProjectVisitor) or [`withDependenciesProjectVisitor`](#withDependenciesProjectVisitor).
-} -}
newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext {} newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext { canAddModuleVisitor : () }
newProjectRuleSchema name_ initialProjectContext = newProjectRuleSchema name_ initialProjectContext =
ProjectRuleSchema ProjectRuleSchema
{ name = name_ { name = name_
@ -962,8 +962,8 @@ fromProjectRuleSchema (ProjectRuleSchema schema) =
-} -}
withModuleVisitor : withModuleVisitor :
(ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : () }
-> ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : Required } -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required }
withModuleVisitor visitor (ProjectRuleSchema schema) = withModuleVisitor visitor (ProjectRuleSchema schema) =
let let
previousModuleVisitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) previousModuleVisitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext)
@ -994,7 +994,7 @@ 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 | withModuleContext : Required } -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required }
-> ProjectRuleSchema projectContext moduleContext schemaState -> ProjectRuleSchema projectContext moduleContext schemaState
withModuleContext moduleContext (ProjectRuleSchema schema) = withModuleContext moduleContext (ProjectRuleSchema schema) =
let let

View File

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