diff --git a/phantom-type-tests/No_WithModuleContext_Without_WithModuleVisitor.txt b/phantom-type-tests/No_WithModuleContext_Without_WithModuleVisitor.txt index 7d265b18..17d2d935 100644 --- a/phantom-type-tests/No_WithModuleContext_Without_WithModuleVisitor.txt +++ b/phantom-type-tests/No_WithModuleContext_Without_WithModuleVisitor.txt @@ -11,12 +11,18 @@ This function cannot handle the argument sent through the (|>) pipe: The argument is: - Rule.ProjectRuleSchema () () {} + Rule.ProjectRuleSchema () () { canAddModuleVisitor : () } But (|>) is piping it to a function that expects: 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! diff --git a/phantom-type-tests/No_WithModuleVisitor_After_WithModuleContext.elm b/phantom-type-tests/No_WithModuleVisitor_After_WithModuleContext.elm new file mode 100644 index 00000000..3572e3a1 --- /dev/null +++ b/phantom-type-tests/No_WithModuleVisitor_After_WithModuleContext.elm @@ -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 (\_ () -> ( [], () )) diff --git a/phantom-type-tests/No_WithModuleVisitor_After_WithModuleContext.txt b/phantom-type-tests/No_WithModuleVisitor_After_WithModuleContext.txt new file mode 100644 index 00000000..e69de29b diff --git a/phantom-type-tests/WithModuleContext_AtMostOnce.txt b/phantom-type-tests/WithModuleContext_AtMostOnce.txt index 108fd371..682de23f 100644 --- a/phantom-type-tests/WithModuleContext_AtMostOnce.txt +++ b/phantom-type-tests/WithModuleContext_AtMostOnce.txt @@ -17,12 +17,18 @@ This function cannot handle the argument sent through the (|>) pipe: The argument is: - Rule.ProjectRuleSchema () () {} + Rule.ProjectRuleSchema () () { canAddModuleVisitor : () } But (|>) is piping it to a function that expects: 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! diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index bf60940a..464f6967 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -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 {} +newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema projectContext moduleContext { canAddModuleVisitor : () } newProjectRuleSchema name_ initialProjectContext = ProjectRuleSchema { name = name_ @@ -962,8 +962,8 @@ fromProjectRuleSchema (ProjectRuleSchema schema) = -} withModuleVisitor : (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) - -> ProjectRuleSchema projectContext moduleContext schemaState - -> ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : Required } + -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : () } + -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required } withModuleVisitor visitor (ProjectRuleSchema schema) = let previousModuleVisitors : List (ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext) @@ -994,7 +994,7 @@ withModuleContext : , fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext , foldProjectContexts : projectContext -> projectContext -> projectContext } - -> ProjectRuleSchema projectContext moduleContext { schemaState | withModuleContext : Required } + -> ProjectRuleSchema projectContext moduleContext { schemaState | canAddModuleVisitor : (), withModuleContext : Required } -> ProjectRuleSchema projectContext moduleContext schemaState withModuleContext moduleContext (ProjectRuleSchema schema) = let diff --git a/src/Scope2.elm b/src/Scope2.elm index 8ab2bb6f..89e3d801 100644 --- a/src/Scope2.elm +++ b/src/Scope2.elm @@ -167,8 +167,8 @@ emptyScope = addProjectVisitors : - Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } schemaState - -> Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } { schemaState | withModuleContext : Rule.Required } + Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } { schemaState | canAddModuleVisitor : () } + -> Rule.ProjectRuleSchema { projectContext | scope : ProjectContext } { moduleContext | scope : ModuleContext } { schemaState | canAddModuleVisitor : (), withModuleContext : Rule.Required } addProjectVisitors schema = schema |> Rule.withContextFromImportedModules