Skip to content

Commit

Permalink
Add Rule.withModuleNameNode
Browse files Browse the repository at this point in the history
  • Loading branch information
jfmengels committed Apr 28, 2022
1 parent d17d995 commit 0fe88c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs.json

Large diffs are not rendered by default.

25 changes: 23 additions & 2 deletions src/Review/Rule.elm
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Review.Rule exposing
, withFinalModuleEvaluation
, withElmJsonModuleVisitor, withReadmeModuleVisitor, withDependenciesModuleVisitor
, 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
, Error, error, errorWithFix, ModuleKey, errorForModule, errorForModuleWithFix, ElmJsonKey, errorForElmJson, errorForElmJsonWithFix, ReadmeKey, errorForReadme, errorForReadmeWithFix
, globalError, configurationError
Expand Down Expand Up @@ -224,7 +224,7 @@ first, as they are in practice a simpler version of project rules.
## 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
Expand Down Expand Up @@ -5070,6 +5070,27 @@ withModuleName (ContextCreator fn 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.
When encountering a `Expression.FunctionOrValue ModuleName String` (among other nodes where we refer to a function or value),
Expand Down

0 comments on commit 0fe88c9

Please sign in to comment.