From 0cada05fe39adaeebca251f30283f0c6ca1cd026 Mon Sep 17 00:00:00 2001 From: Jeroen Engels Date: Sun, 26 Jan 2020 20:40:14 +0100 Subject: [PATCH] Rename withElmJsonVisitor to withModuleElmJsonVisitor --- ...onVisitorForModuleVisitorInProjectRule.elm | 2 +- src/Review/Project.elm | 3 ++- src/Review/Rule.elm | 25 +++++++++---------- tests/Review/RuleVisitorsOrderTest.elm | 4 +-- tests/ScopeTest.elm | 2 +- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/phantom-type-tests/NoElmJsonVisitorForModuleVisitorInProjectRule.elm b/phantom-type-tests/NoElmJsonVisitorForModuleVisitorInProjectRule.elm index 26d40724..6ed659bc 100644 --- a/phantom-type-tests/NoElmJsonVisitorForModuleVisitorInProjectRule.elm +++ b/phantom-type-tests/NoElmJsonVisitorForModuleVisitorInProjectRule.elm @@ -1,6 +1,6 @@ module NoWithInitialContextAfterHavingAddedAVisitor exposing (rule) -{-| We want to forbid module visitors from using `withElmJsonVisitor`. +{-| We want to forbid module visitors from using `withModuleElmJsonVisitor`. # Rule diff --git a/src/Review/Project.elm b/src/Review/Project.elm index 3c3d4eda..e778ccd1 100644 --- a/src/Review/Project.elm +++ b/src/Review/Project.elm @@ -271,7 +271,8 @@ type alias ElmJson = {-| Add the content of the `elm.json` file to the project details, making it available for rules to access using -[`Review.Rule.withElmJsonVisitor`](./Review-Rule#withElmJsonVisitor). +[`Review.Rule.withModuleElmJsonVisitor`](./Review-Rule#withModuleElmJsonVisitor) and +[`Review.Rule.withProjectElmJsonVisitor`](./Review-Rule#withProjectElmJsonVisitor). -} withElmJson : ElmJson -> Project -> Project withElmJson elmJson_ (Project project) = diff --git a/src/Review/Rule.elm b/src/Review/Rule.elm index 27bcf191..9f557437 100644 --- a/src/Review/Rule.elm +++ b/src/Review/Rule.elm @@ -4,7 +4,7 @@ module Review.Rule exposing , newModuleRuleSchema, fromModuleRuleSchema , withSimpleModuleDefinitionVisitor, withSimpleCommentsVisitor, withSimpleImportVisitor, withSimpleDeclarationVisitor, withSimpleExpressionVisitor , withModuleDefinitionVisitor, withCommentsVisitor, withImportVisitor, Direction(..), withDeclarationVisitor, withDeclarationListVisitor, withExpressionVisitor, withFinalModuleEvaluation - , withElmJsonVisitor, withDependenciesVisitor + , withModuleElmJsonVisitor, withDependenciesVisitor , withFixes , Error, error, parsingError, errorRuleName, errorMessage, errorDetails, errorRange, errorFixes, errorFilePath , newProjectRuleSchema, fromProjectRuleSchema, traversingImportedModulesFirst, withProjectElmJsonVisitor, withProjectDependenciesVisitor, withFinalProjectEvaluation @@ -23,7 +23,7 @@ Then, for each module and rule, it will give the details of your project (like t contents of the file to analyze to the rule. The order in which things get passed to the rule is the following: - Read project-related info (only collect data in these steps) - - The `elm.json` file, visited by [`withElmJsonVisitor`](#withElmJsonVisitor) + - The `elm.json` file, visited by [`withModuleElmJsonVisitor`](#withModuleElmJsonVisitor) - The definition for dependencies, visited by [`withDependenciesVisitor`](#withDependenciesVisitor) - Visit the file (in the following order) - The module definition, visited by [`withSimpleModuleDefinitionVisitor`](#withSimpleModuleDefinitionVisitor) and [`withModuleDefinitionVisitor`](#withModuleDefinitionVisitor) @@ -175,7 +175,7 @@ patterns you would want to forbid, but that are not handled by the example. ## Builder functions to analyze the project's data -@docs withElmJsonVisitor, withDependenciesVisitor +@docs withModuleElmJsonVisitor, withDependenciesVisitor ## Automatic fixing @@ -194,7 +194,6 @@ For more information on automatic fixing, read the documentation for [`Review.Fi @docs newProjectRuleSchema, fromProjectRuleSchema, traversingImportedModulesFirst, withProjectElmJsonVisitor, withProjectDependenciesVisitor, withFinalProjectEvaluation @docs FileKey, errorForFile -@docs ReviewResult -} @@ -216,9 +215,9 @@ import Review.Project exposing (Project, ProjectModule) import Set exposing (Set) -{-| Represents a construct able to analyze a module and report unwanted patterns. -See [`newModuleRuleSchema`](#newModuleRuleSchema), and [`fromModuleRuleSchema`](#fromModuleRuleSchema) for how to create one. -TODO Explain about single and multi-file rules +{-| Represents a construct able to analyze modules from a project and report +unwanted patterns. +See [`newModuleRuleSchema`](#newModuleRuleSchema), and [`newProjectRuleSchema`](#newProjectRuleSchema) for how to create one. -} type Rule = ModuleRule String (Project -> ( List Error, Rule )) @@ -364,7 +363,7 @@ take a look at [`withInitialContext`](#withInitialContext) and "with\*" function newModuleRuleSchema : String -> context - -> ModuleRuleSchema { withElmJsonVisitor : (), withDependenciesVisitor : () } context + -> ModuleRuleSchema { withModuleElmJsonVisitor : (), withDependenciesVisitor : () } context newModuleRuleSchema name_ context = emptySchema name_ context @@ -1268,7 +1267,7 @@ The following example forbids exposing a file in an "Internal" directory in your rule : Rule rule = Rule.newModuleRuleSchema "DoNoExposeInternalModules" Nothing - |> Rule.withElmJsonVisitor elmJsonVisitor + |> Rule.withModuleElmJsonVisitor elmJsonVisitor |> Rule.withModuleDefinitionVisitor moduleDefinitionVisitor |> Rule.fromModuleRuleSchema @@ -1312,11 +1311,11 @@ The following example forbids exposing a file in an "Internal" directory in your ( [], context ) -} -withElmJsonVisitor : +withModuleElmJsonVisitor : (Maybe Elm.Project.Project -> context -> context) - -> ModuleRuleSchema { anything | withElmJsonVisitor : () } context - -> ModuleRuleSchema { anything | withElmJsonVisitor : () } context -withElmJsonVisitor visitor (ModuleRuleSchema schema) = + -> ModuleRuleSchema { anything | withModuleElmJsonVisitor : () } context + -> ModuleRuleSchema { anything | withModuleElmJsonVisitor : () } context +withModuleElmJsonVisitor visitor (ModuleRuleSchema schema) = ModuleRuleSchema { schema | elmJsonVisitors = visitor :: schema.elmJsonVisitors } diff --git a/tests/Review/RuleVisitorsOrderTest.elm b/tests/Review/RuleVisitorsOrderTest.elm index d69188ab..d8bbd3dd 100644 --- a/tests/Review/RuleVisitorsOrderTest.elm +++ b/tests/Review/RuleVisitorsOrderTest.elm @@ -28,7 +28,7 @@ all = rule : Rule rule = Rule.newModuleRuleSchema "TestRule" "\n0 - withInitialContext" - |> Rule.withElmJsonVisitor (\_ context -> context ++ "\n1 - withElmJsonVisitor") + |> Rule.withModuleElmJsonVisitor (\_ context -> context ++ "\n1 - withModuleElmJsonVisitor") |> Rule.withDependenciesVisitor (\_ context -> context ++ "\n2 - withDependenciesVisitor") |> Rule.withModuleDefinitionVisitor (\_ context -> ( [], context ++ "\n3 - withModuleDefinitionVisitor" )) |> Rule.withImportVisitor (\_ context -> ( [], context ++ "\n4 - withImportVisitor" )) @@ -70,7 +70,7 @@ a = 1 [ Review.Test.error { message = """ 0 - withInitialContext -1 - withElmJsonVisitor +1 - withModuleElmJsonVisitor 2 - withDependenciesVisitor 3 - withModuleDefinitionVisitor 4 - withImportVisitor diff --git a/tests/ScopeTest.elm b/tests/ScopeTest.elm index 5f8b9427..9508778e 100644 --- a/tests/ScopeTest.elm +++ b/tests/ScopeTest.elm @@ -34,7 +34,7 @@ baseRule : Rule.ModuleRuleSchema { hasAtLeastOneVisitor : () , withDependenciesVisitor : () - , withElmJsonVisitor : () + , withModuleElmJsonVisitor : () } Context baseRule =