Add Rule.withModuleNameNode

This commit is contained in:
Jeroen Engels 2022-04-28 11:52:21 +02:00
parent d17d995f0e
commit 0fe88c90cf
2 changed files with 24 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -13,7 +13,7 @@ module Review.Rule exposing
, withFinalModuleEvaluation , withFinalModuleEvaluation
, withElmJsonModuleVisitor, withReadmeModuleVisitor, withDependenciesModuleVisitor , withElmJsonModuleVisitor, withReadmeModuleVisitor, withDependenciesModuleVisitor
, ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withContextFromImportedModules , ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withContextFromImportedModules
, ContextCreator, initContextCreator, isInSourceDirectories, withModuleName, withFilePath, withModuleNameLookupTable, withModuleKey, withSourceCodeExtractor , ContextCreator, initContextCreator, isInSourceDirectories, withModuleName, withModuleNameNode, withFilePath, withModuleNameLookupTable, withModuleKey, withSourceCodeExtractor
, Metadata, moduleNameFromMetadata, moduleNameNodeFromMetadata, withMetadata , Metadata, moduleNameFromMetadata, moduleNameNodeFromMetadata, withMetadata
, Error, error, errorWithFix, ModuleKey, errorForModule, errorForModuleWithFix, ElmJsonKey, errorForElmJson, errorForElmJsonWithFix, ReadmeKey, errorForReadme, errorForReadmeWithFix , Error, error, errorWithFix, ModuleKey, errorForModule, errorForModuleWithFix, ElmJsonKey, errorForElmJson, errorForElmJsonWithFix, ReadmeKey, errorForReadme, errorForReadmeWithFix
, globalError, configurationError , globalError, configurationError
@ -224,7 +224,7 @@ first, as they are in practice a simpler version of project rules.
## Requesting more information ## Requesting more information
@docs ContextCreator, initContextCreator, isInSourceDirectories, withModuleName, withFilePath, withModuleNameLookupTable, withModuleKey, withSourceCodeExtractor @docs ContextCreator, initContextCreator, isInSourceDirectories, withModuleName, withModuleNameNode, withFilePath, withModuleNameLookupTable, withModuleKey, withSourceCodeExtractor
@docs Metadata, moduleNameFromMetadata, moduleNameNodeFromMetadata, withMetadata @docs Metadata, moduleNameFromMetadata, moduleNameNodeFromMetadata, withMetadata
@ -5070,6 +5070,27 @@ withModuleName (ContextCreator fn requestedData) =
requestedData requestedData
{-| Request the node corresponding to the name of the module.
contextCreator : Rule.ContextCreator () Context
contextCreator =
Rule.initContextCreator
(\moduleNameNode () ->
{ moduleNameNode = moduleNameNode
-- ...other fields
}
)
|> Rule.withModuleNameNode
-}
withModuleNameNode : ContextCreator (Node ModuleName) (from -> to) -> ContextCreator from to
withModuleNameNode (ContextCreator fn requestedData) =
ContextCreator
(\data -> fn data (moduleNameNodeFromMetadata data.metadata))
requestedData
{-| Requests the module name lookup table for the types and functions inside a module. {-| Requests the module name lookup table for the types and functions inside a module.
When encountering a `Expression.FunctionOrValue ModuleName String` (among other nodes where we refer to a function or value), When encountering a `Expression.FunctionOrValue ModuleName String` (among other nodes where we refer to a function or value),