Add a requested files field

This commit is contained in:
Jeroen Engels 2023-05-31 10:26:04 +02:00
parent 004d6a2496
commit 50f869a431
2 changed files with 21 additions and 6 deletions

View File

@ -397,13 +397,17 @@ type alias ModuleRuleSchemaData moduleContext =
-- Project visitors
, elmJsonVisitor : Maybe (Maybe Elm.Project.Project -> moduleContext -> moduleContext)
, arbitraryFilesVisitor : Maybe (List { path : String, content : String } -> moduleContext -> moduleContext)
, arbitraryFilesVisitor : Maybe ( List { path : String, content : String } -> moduleContext -> moduleContext, ArbitraryFileRequest )
, readmeVisitor : Maybe (Maybe String -> moduleContext -> moduleContext)
, dependenciesVisitor : Maybe (Dict String Review.Project.Dependency.Dependency -> moduleContext -> moduleContext)
, directDependenciesVisitor : Maybe (Dict String Review.Project.Dependency.Dependency -> moduleContext -> moduleContext)
}
type alias ArbitraryFileRequest =
List String
-- REVIEWING
@ -1106,7 +1110,7 @@ fromModuleRuleSchema ((ModuleRuleSchema schema) as moduleVisitor) =
{ name = schema.name
, initialProjectContext = initialModuleContext
, elmJsonVisitor = compactProjectDataVisitors (Maybe.map .project) schema.elmJsonVisitor
, arbitraryFilesVisitor = compactProjectDataVisitors identity schema.arbitraryFilesVisitor
, arbitraryFilesVisitor = compactProjectDataVisitors identity (Maybe.map Tuple.first schema.arbitraryFilesVisitor)
, readmeVisitor = compactProjectDataVisitors (Maybe.map .content) schema.readmeVisitor
, directDependenciesVisitor = compactProjectDataVisitors identity schema.directDependenciesVisitor
, dependenciesVisitor = compactProjectDataVisitors identity schema.dependenciesVisitor
@ -2295,11 +2299,22 @@ withElmJsonModuleVisitor visitor (ModuleRuleSchema schema) =
the project's `README.md` file.
-}
withArbitraryFilesModuleVisitor :
(List { path : String, content : String } -> moduleContext -> moduleContext)
ArbitraryFileRequest
-> (List { path : String, content : String } -> moduleContext -> moduleContext)
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
withArbitraryFilesModuleVisitor visitor (ModuleRuleSchema schema) =
ModuleRuleSchema { schema | arbitraryFilesVisitor = Just (combineContextOnlyVisitor visitor schema.arbitraryFilesVisitor) }
withArbitraryFilesModuleVisitor newRequestedFiles newVisitor (ModuleRuleSchema schema) =
let
arbitraryFilesVisitor : ( List { path : String, content : String } -> moduleContext -> moduleContext, ArbitraryFileRequest )
arbitraryFilesVisitor =
case schema.arbitraryFilesVisitor of
Just ( existingVisitor, existingRequestedFiles ) ->
( combineContextOnlyVisitor newVisitor (Just existingVisitor), newRequestedFiles ++ existingRequestedFiles )
Nothing ->
( newVisitor, newRequestedFiles )
in
ModuleRuleSchema { schema | arbitraryFilesVisitor = Just arbitraryFilesVisitor }
{-| Add a visitor to the [`ModuleRuleSchema`](#ModuleRuleSchema) which will visit

View File

@ -37,7 +37,7 @@ type alias Context =
rule : Rule
rule =
Rule.newModuleRuleSchema "WithCommentsVisitorTestRule" []
|> Rule.withArbitraryFilesModuleVisitor arbitraryFilesModuleVisitor
|> Rule.withArbitraryFilesModuleVisitor [ "foo/*.css" ] arbitraryFilesModuleVisitor
|> Rule.withModuleDefinitionVisitor (\_ context -> ( [], context ))
|> Rule.withFinalModuleEvaluation finalEvaluation
|> Rule.fromModuleRuleSchema