mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-12-24 02:02:29 +03:00
Move initial project context to an argument of Rule.newProjectRuleSchema
This commit is contained in:
parent
2ab777e6f6
commit
ce7c6b7021
@ -34,8 +34,8 @@ import Set exposing (Set)
|
||||
rule : Configuration -> Rule
|
||||
rule configuration =
|
||||
Rule.newProjectRuleSchema "NoInvalidLicense"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -127,8 +127,8 @@ type alias ModuleContext =
|
||||
ProjectContext
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ elmJsonKey = Nothing
|
||||
, licenses = Dict.empty
|
||||
, directProjectDependencies = Set.empty
|
||||
|
@ -78,8 +78,8 @@ in your editor, rather than when running your tests or [elm-xref](https://github
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "NoUnused.CustomTypeConstructors"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -148,9 +148,9 @@ type alias ModuleContext =
|
||||
}
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
{ scope = Scope.initProjectContext
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ scope = Scope.initialProjectContext
|
||||
, exposedModules = Set.empty
|
||||
, exposedConstructors = Dict.empty
|
||||
, usedConstructors = Dict.empty
|
||||
|
@ -47,8 +47,8 @@ unused modules in your application or package.
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "NoUnused.Dependencies"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -97,8 +97,8 @@ type alias ModuleContext =
|
||||
Set String
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ moduleNameToDependency = Dict.empty
|
||||
, directProjectDependencies = Set.empty
|
||||
, importedModuleNames = Set.empty
|
||||
|
@ -54,8 +54,8 @@ unused modules in your application or package.
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "NoUnused.Exports"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -112,9 +112,9 @@ type alias ModuleContext =
|
||||
}
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
{ scope = Scope.initProjectContext
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ scope = Scope.initialProjectContext
|
||||
, projectType = IsApplication
|
||||
, modules = Dict.empty
|
||||
, used = Set.empty
|
||||
|
@ -47,8 +47,8 @@ unused modules in your application or package.
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "NoUnused.Modules"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -87,8 +87,8 @@ type alias ModuleContext =
|
||||
}
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ modules = Dict.empty
|
||||
, usedModules = Set.singleton [ "ReviewConfig" ]
|
||||
, isPackage = False
|
||||
|
@ -9,8 +9,8 @@ import Review.Rule as Rule exposing (Error, Rule)
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "ReadmeStartsWithProjectTitle"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -31,8 +31,8 @@ type alias ProjectContext =
|
||||
}
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ projectTitle = Nothing
|
||||
}
|
||||
|
||||
|
@ -712,9 +712,9 @@ how to create a project rule.
|
||||
type ProjectRuleSchema projectContext moduleContext
|
||||
= ProjectRuleSchema
|
||||
{ name : String
|
||||
, initialProjectContext : projectContext
|
||||
, context :
|
||||
{ initProjectContext : projectContext
|
||||
, fromProjectToModule : ModuleKey -> Node ModuleName -> projectContext -> moduleContext
|
||||
{ fromProjectToModule : ModuleKey -> Node ModuleName -> projectContext -> moduleContext
|
||||
, fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
, foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
}
|
||||
@ -768,8 +768,8 @@ Let's go through an example of a rule that reports unused modules.
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "NoUnused.Modules"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -830,13 +830,13 @@ At the project level, we are interested in 3 things. 1) The declared modules
|
||||
that may have to be reported. This is a dictionary containing a [`Rule.ModuleKey`](#ModuleKey),
|
||||
which we need to report errors in the final module evaluation. 2) The set of modules for which we found an import. 3) whether the project is a package.
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
{ declaredModules = Dict.empty
|
||||
, usedModules = Set.empty
|
||||
}
|
||||
|
||||
`initProjectContext` defines the initial value for the project context.
|
||||
`initialProjectContext` defines the initial value for the project context.
|
||||
It's equivalent to the second argument of ['newModuleRuleSchema'](#newModuleRuleSchema).
|
||||
|
||||
fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> ProjectContext -> ModuleContext
|
||||
@ -878,7 +878,7 @@ This function also gives you access to the module key for the file that TODO
|
||||
`foldProjectContexts` is how we fold/reduce/merge the project contexts. The arguments
|
||||
are in the same order as [`List.foldl`](https://package.elm-lang.org/packages/elm/core/latest/List#foldl),
|
||||
meaning the initial/accumulated value is the second. It may help to imagine that
|
||||
the second argument is `initProjectContext`.
|
||||
the second argument is `initialProjectContext`.
|
||||
|
||||
You may have wondered why we have a collection of declared modules and another
|
||||
of used modules, and not a single collection where we remove modules every time
|
||||
@ -931,20 +931,20 @@ in project rules. Instead, you should use [`withElmJsonProjectVisitor`](#withElm
|
||||
-}
|
||||
newProjectRuleSchema :
|
||||
String
|
||||
-> projectContext
|
||||
->
|
||||
{ moduleVisitor : ModuleRuleSchema {} moduleContext -> ModuleRuleSchema { hasAtLeastOneVisitor : () } moduleContext
|
||||
, initProjectContext : projectContext
|
||||
, fromProjectToModule : ModuleKey -> Node ModuleName -> projectContext -> moduleContext
|
||||
, fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
, foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
}
|
||||
-> ProjectRuleSchema projectContext moduleContext
|
||||
newProjectRuleSchema name_ { moduleVisitor, initProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts } =
|
||||
newProjectRuleSchema name_ initialProjectContext { moduleVisitor, fromProjectToModule, fromModuleToProject, foldProjectContexts } =
|
||||
ProjectRuleSchema
|
||||
{ name = name_
|
||||
, initialProjectContext = initialProjectContext
|
||||
, context =
|
||||
{ initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
{ fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
}
|
||||
@ -1159,7 +1159,7 @@ runProjectRule ((ProjectRuleSchema schema) as wrappedSchema) startCache exceptio
|
||||
)
|
||||
|
||||
( projectRelatedErrors, initialContext ) =
|
||||
( [], schema.context.initProjectContext )
|
||||
( [], schema.initialProjectContext )
|
||||
|> accumulateWithListOfVisitors schema.elmJsonVisitors elmJsonData
|
||||
|> accumulateWithListOfVisitors schema.readmeVisitors readmeData
|
||||
|> accumulateWithListOfVisitors schema.dependenciesVisitors (Review.Project.dependencies project)
|
||||
|
@ -1,6 +1,6 @@
|
||||
module Scope2 exposing
|
||||
( ProjectContext, ModuleContext
|
||||
, addProjectVisitors, addModuleVisitors, initProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts
|
||||
, addProjectVisitors, addModuleVisitors, initialProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts
|
||||
, realFunctionOrType
|
||||
)
|
||||
|
||||
@ -14,7 +14,7 @@ module Scope2 exposing
|
||||
|
||||
# Usage
|
||||
|
||||
@docs addProjectVisitors, addModuleVisitors, initProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts
|
||||
@docs addProjectVisitors, addModuleVisitors, initialProjectContext, fromProjectToModule, fromModuleToProject, foldProjectContexts
|
||||
|
||||
|
||||
# Access
|
||||
@ -56,7 +56,7 @@ import Review.Rule as Rule exposing (Direction)
|
||||
\schema ->
|
||||
schema
|
||||
|> Rule.withModuleDefinitionVisitor moduleDefinitionVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -107,8 +107,8 @@ type alias Scope =
|
||||
-- USAGE
|
||||
|
||||
|
||||
initProjectContext : ProjectContext
|
||||
initProjectContext =
|
||||
initialProjectContext : ProjectContext
|
||||
initialProjectContext =
|
||||
ProjectContext
|
||||
{ dependenciesModules = Dict.empty
|
||||
, modules = Dict.empty
|
||||
@ -222,7 +222,6 @@ addModuleVisitors schema =
|
||||
-- }
|
||||
-- ->
|
||||
-- { moduleVisitor : Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasNoVisitor : () } moduleContext -> Rule.ModuleRuleSchema Rule.ForLookingAtSeveralFiles { hasAtLeastOneVisitor : () } moduleContext
|
||||
-- , initProjectContext : projectContext
|
||||
-- , fromProjectToModule : Rule.ModuleKey -> Node ModuleName -> projectContext -> moduleContext
|
||||
-- , fromModuleToProject : Rule.ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
-- , foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
|
@ -16,8 +16,8 @@ type alias Context =
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "TestRule"
|
||||
initialProjectContext
|
||||
{ moduleVisitor = moduleVisitor
|
||||
, initProjectContext = initProjectContext
|
||||
, fromProjectToModule = fromProjectToModule
|
||||
, fromModuleToProject = fromModuleToProject
|
||||
, foldProjectContexts = foldProjectContexts
|
||||
@ -33,8 +33,8 @@ moduleVisitor schema =
|
||||
|> Rule.withModuleDefinitionVisitor (\moduleNode context -> ( [], context ))
|
||||
|
||||
|
||||
initProjectContext : Context
|
||||
initProjectContext =
|
||||
initialProjectContext : Context
|
||||
initialProjectContext =
|
||||
Nothing
|
||||
|
||||
|
||||
|
@ -127,6 +127,7 @@ project =
|
||||
rule : Rule
|
||||
rule =
|
||||
Rule.newProjectRuleSchema "TestRule"
|
||||
{ scope = Scope.initialProjectContext }
|
||||
{ moduleVisitor =
|
||||
\schema ->
|
||||
schema
|
||||
@ -134,7 +135,6 @@ rule =
|
||||
|> Rule.withDeclarationVisitor declarationVisitor
|
||||
|> Rule.withExpressionVisitor expressionVisitor
|
||||
|> Rule.withFinalModuleEvaluation finalEvaluation
|
||||
, initProjectContext = { scope = Scope.initProjectContext }
|
||||
, fromProjectToModule =
|
||||
\moduleKey moduleNameNode projectContext ->
|
||||
{ scope = Scope.fromProjectToModule projectContext.scope
|
||||
|
Loading…
Reference in New Issue
Block a user