mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-23 23:05:35 +03:00
Turn Folder into a Context
This commit is contained in:
parent
d1a16cc83d
commit
df86632c1d
@ -1,16 +1,14 @@
|
||||
module Review.Context exposing (AvailableData, Context, RequestedData, apply, init, withMetadata, withModuleKey)
|
||||
|
||||
import Elm.Syntax.Node as Node
|
||||
import Elm.Syntax.Range as Range
|
||||
import Review.Metadata as Metadata exposing (Metadata)
|
||||
import Review.Metadata exposing (Metadata)
|
||||
import Review.Rule exposing (ModuleKey)
|
||||
|
||||
|
||||
type Context projectContext moduleContext
|
||||
= Context (AvailableData -> projectContext -> moduleContext) RequestedData
|
||||
type Context from to
|
||||
= Context (AvailableData -> from -> to) RequestedData
|
||||
|
||||
|
||||
init : (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
init : (from -> to) -> Context from to
|
||||
init fromProjectToModule =
|
||||
Context
|
||||
(always fromProjectToModule)
|
||||
@ -23,14 +21,14 @@ type RequestedData
|
||||
}
|
||||
|
||||
|
||||
withMetadata : Context Metadata (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
withMetadata : Context Metadata (from -> to) -> Context from to
|
||||
withMetadata (Context fn (RequestedData requested)) =
|
||||
Context
|
||||
(\data -> fn data data.metadata)
|
||||
(RequestedData { requested | metadata = True })
|
||||
|
||||
|
||||
withModuleKey : Context ModuleKey (projectContext -> moduleContext) -> Context projectContext moduleContext
|
||||
withModuleKey : Context ModuleKey (from -> to) -> Context from to
|
||||
withModuleKey (Context fn (RequestedData requested)) =
|
||||
Context
|
||||
(\data -> fn data data.moduleKey)
|
||||
@ -43,12 +41,12 @@ type alias AvailableData =
|
||||
}
|
||||
|
||||
|
||||
apply : AvailableData -> Context projectContext moduleContext -> projectContext -> moduleContext
|
||||
apply data (Context fn _) projectContext =
|
||||
fn data projectContext
|
||||
apply : AvailableData -> Context from to -> from -> to
|
||||
apply data (Context fn _) from =
|
||||
fn data from
|
||||
|
||||
|
||||
requestedData : Context projectContext moduleContext -> RequestedData
|
||||
requestedData : Context from to -> RequestedData
|
||||
requestedData (Context _ requested) =
|
||||
requested
|
||||
|
||||
|
@ -46,7 +46,7 @@ import Review.Project exposing (Project, ProjectModule)
|
||||
import Review.Project.Dependency
|
||||
import Review.Project.Internal
|
||||
import Review.Rule exposing (CacheEntry, CacheEntryFor, Direction(..), ElmJsonKey(..), Error(..), Forbidden, ModuleKey(..), ModuleRuleResultCache, ModuleVisitorFunctions, ProjectRuleCache, ReadmeKey(..), Required, Rule(..), TraversalType(..), Visitor, accumulateList, accumulateWithListOfVisitors, makeFinalEvaluation, moduleNameNode, removeErrorPhantomType, setFilePathIfUnset, setRuleName, visitDeclaration, visitImport)
|
||||
import Review.Visitor
|
||||
import Review.Visitor exposing (Folder)
|
||||
import Vendor.Graph as Graph exposing (Graph)
|
||||
|
||||
|
||||
@ -67,13 +67,6 @@ type ProjectRuleSchema schemaState projectContext moduleContext
|
||||
}
|
||||
|
||||
|
||||
type alias Folder projectContext moduleContext =
|
||||
{ -- TODO Make this `Context moduleContext projectContext`?
|
||||
fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
, foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
}
|
||||
|
||||
|
||||
newProjectRuleSchema : String -> projectContext -> ProjectRuleSchema { canAddModuleVisitor : (), withModuleContext : Forbidden } projectContext moduleContext
|
||||
newProjectRuleSchema name initialProjectContext =
|
||||
ProjectRuleSchema
|
||||
@ -158,13 +151,13 @@ withModuleContext :
|
||||
}
|
||||
-> ProjectRuleSchema { schemaState | canAddModuleVisitor : (), withModuleContext : Required } projectContext moduleContext
|
||||
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : (), withModuleContext : Forbidden } projectContext moduleContext
|
||||
withModuleContext moduleContext (ProjectRuleSchema schema) =
|
||||
withModuleContext functions (ProjectRuleSchema schema) =
|
||||
let
|
||||
moduleContextCreator : Context projectContext moduleContext
|
||||
moduleContextCreator =
|
||||
Context.init
|
||||
(\moduleKey metadata projectContext ->
|
||||
moduleContext.fromProjectToModule
|
||||
functions.fromProjectToModule
|
||||
moduleKey
|
||||
(Metadata.moduleNameNode metadata)
|
||||
projectContext
|
||||
@ -177,8 +170,11 @@ withModuleContext moduleContext (ProjectRuleSchema schema) =
|
||||
| moduleContextCreator = Just moduleContextCreator
|
||||
, folder =
|
||||
Just
|
||||
{ fromModuleToProject = moduleContext.fromModuleToProject
|
||||
, foldProjectContexts = moduleContext.foldProjectContexts
|
||||
{ fromModuleToProject =
|
||||
Context.init (\moduleKey metadata moduleContext -> functions.fromModuleToProject moduleKey (Metadata.moduleNameNode metadata) moduleContext)
|
||||
|> Context.withModuleKey
|
||||
|> Context.withMetadata
|
||||
, foldProjectContexts = functions.foldProjectContexts
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,7 @@ type alias RunnableProjectVisitor projectContext moduleContext =
|
||||
|
||||
|
||||
type alias Folder projectContext moduleContext =
|
||||
{ -- TODO Make this `Context moduleContext projectContext`
|
||||
fromModuleToProject : ModuleKey -> Node ModuleName -> moduleContext -> projectContext
|
||||
{ fromModuleToProject : Context moduleContext projectContext
|
||||
, foldProjectContexts : projectContext -> projectContext -> projectContext
|
||||
}
|
||||
|
||||
@ -383,10 +382,7 @@ computeModules projectVisitor ( moduleVisitor, moduleContextCreator ) project in
|
||||
, context =
|
||||
case projectVisitor.folder of
|
||||
Just { fromModuleToProject } ->
|
||||
fromModuleToProject
|
||||
moduleKey
|
||||
moduleNameNode_
|
||||
context
|
||||
Context.apply availableData fromModuleToProject context
|
||||
|
||||
Nothing ->
|
||||
initialProjectContext
|
||||
|
Loading…
Reference in New Issue
Block a user