Name things extra files instead of arbitrary files

This commit is contained in:
Jeroen Engels 2023-06-02 16:55:48 +02:00
parent e739f882e4
commit ea44cf22bb
6 changed files with 107 additions and 107 deletions

View File

@ -1,4 +1,4 @@
module Review.Cache.ArbitraryFile exposing
module Review.Cache.ExtraFile exposing
( Entry, create
, match
, errors, errorsForMaybe, setErrors

View File

@ -3,7 +3,7 @@ module Review.Project exposing
, ProjectModule, addModule, addParsedModule, removeModule, modules, modulesThatFailedToParse, precomputeModuleGraph
, addElmJson, elmJson
, addReadme, readme
, addArbitraryFiles
, addExtraFiles
, addDependency, removeDependency, removeDependencies, directDependencies, dependencies
)
@ -38,7 +38,7 @@ does not look at project information (like the `elm.json`, dependencies, ...).
# REPLACEME
@docs addArbitraryFiles
@docs addExtraFiles
# Project dependencies
@ -85,7 +85,7 @@ new =
, modulesThatFailedToParse = []
, elmJson = Nothing
, readme = Nothing
, arbitraryFiles = []
, extraFiles = []
, dependencies = Dict.empty
, moduleGraph = Nothing
, sourceDirectories = [ "src/" ]
@ -302,9 +302,9 @@ addReadme readme_ (Internal.Project project) =
{-| REPLACEME
-}
addArbitraryFiles : List { path : String, content : String } -> Project -> Project
addArbitraryFiles files (Internal.Project project) =
Internal.Project { project | arbitraryFiles = List.map (\file -> ( file, ContentHash.hash file.content )) files }
addExtraFiles : List { path : String, content : String } -> Project -> Project
addExtraFiles files (Internal.Project project) =
Internal.Project { project | extraFiles = List.map (\file -> ( file, ContentHash.hash file.content )) files }
{-| Get the contents of the `README.md` file, if available.

View File

@ -25,7 +25,7 @@ type Project
, modulesThatFailedToParse : List { path : String, source : String }
, elmJson : Maybe ( { path : String, raw : String, project : Elm.Project.Project }, ContentHash )
, readme : Maybe ( { path : String, content : String }, ContentHash )
, arbitraryFiles : List ( { path : String, content : String }, ContentHash )
, extraFiles : List ( { path : String, content : String }, ContentHash )
, dependencies : Dict String Dependency
, moduleGraph : Maybe (Graph FilePath ())
, sourceDirectories : List String

View File

@ -3,14 +3,14 @@ module Review.Project.Valid exposing
, addElmJson
, addParsedModule
, addReadme
, arbitraryFiles
, arbitraryFilesHash
, dependencies
, dependenciesHash
, directDependencies
, doesModuleExist
, elmJson
, elmJsonHash
, extraFiles
, extraFilesHash
, getModuleByPath
, moduleGraph
, moduleZipper
@ -52,7 +52,7 @@ type alias ValidProjectData =
, modulesByModuleName : Dict ModuleName OpaqueProjectModule
, elmJson : Maybe ( { path : String, raw : String, project : Elm.Project.Project }, ContentHash )
, readme : Maybe ( { path : String, content : String }, ContentHash )
, arbitraryFiles : List ( { path : String, content : String }, ContentHash )
, extraFiles : List ( { path : String, content : String }, ContentHash )
, dependencies : Dict String Dependency
, directDependencies : Dict String Dependency
, dependencyModules : Set ModuleName
@ -70,7 +70,7 @@ toRegularProject (ValidProject validProject) =
, modulesThatFailedToParse = []
, elmJson = validProject.elmJson
, readme = validProject.readme
, arbitraryFiles = validProject.arbitraryFiles
, extraFiles = validProject.extraFiles
, dependencies = validProject.dependencies
, moduleGraph = Just validProject.moduleGraph
, sourceDirectories = validProject.sourceDirectories
@ -137,7 +137,7 @@ fromProjectAndGraph moduleGraph_ acyclicGraph (Project project) =
, modulesByModuleName = computeModulesByModuleName project.modules
, elmJson = project.elmJson
, readme = project.readme
, arbitraryFiles = project.arbitraryFiles
, extraFiles = project.extraFiles
, dependencies = project.dependencies
, directDependencies = directDependencies_
, dependencyModules = computeDependencyModules directDependencies_
@ -313,14 +313,14 @@ readmeHash (ValidProject project) =
Maybe.map Tuple.second project.readme
arbitraryFiles : ValidProject -> List { path : String, content : String }
arbitraryFiles (ValidProject project) =
List.map Tuple.first project.arbitraryFiles
extraFiles : ValidProject -> List { path : String, content : String }
extraFiles (ValidProject project) =
List.map Tuple.first project.extraFiles
arbitraryFilesHash : ValidProject -> List ContentHash
arbitraryFilesHash (ValidProject project) =
List.map Tuple.second project.arbitraryFiles
extraFilesHash : ValidProject -> List ContentHash
extraFilesHash (ValidProject project) =
List.map Tuple.second project.extraFiles
dependencies : ValidProject -> Dict String Dependency

View File

@ -14,8 +14,8 @@ module Review.Rule exposing
, providesFixesForModuleRule
, withFinalModuleEvaluation
, withElmJsonModuleVisitor, withReadmeModuleVisitor, withDirectDependenciesModuleVisitor, withDependenciesModuleVisitor
, withArbitraryFilesModuleVisitor
, ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDirectDependenciesProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withArbitraryFilesProjectVisitor, withContextFromImportedModules
, withExtraFilesModuleVisitor
, ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDirectDependenciesProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withExtraFilesProjectVisitor, withContextFromImportedModules
, providesFixesForProjectRule
, ContextCreator, initContextCreator, withModuleName, withModuleNameNode, withIsInSourceDirectories, withFilePath, withIsFileIgnored, withModuleNameLookupTable, withModuleKey, withSourceCodeExtractor, withFullAst, withModuleDocumentation
, Metadata, withMetadata, moduleNameFromMetadata, moduleNameNodeFromMetadata, isInSourceDirectories
@ -212,7 +212,7 @@ Evaluating/visiting a node means two things:
## Builder functions to analyze the project's data
@docs withElmJsonModuleVisitor, withReadmeModuleVisitor, withDirectDependenciesModuleVisitor, withDependenciesModuleVisitor
@docs withArbitraryFilesModuleVisitor
@docs withExtraFilesModuleVisitor
## Creating a project rule
@ -228,7 +228,7 @@ Project rules can also report errors in the `elm.json` or the `README.md` files.
If you are new to writing rules, I would recommend learning [how to build a module rule](#creating-a-module-rule)
first, as they are in practice a simpler version of project rules.
@docs ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDirectDependenciesProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withArbitraryFilesProjectVisitor, withContextFromImportedModules
@docs ProjectRuleSchema, newProjectRuleSchema, fromProjectRuleSchema, withModuleVisitor, withModuleContext, withModuleContextUsingContextCreator, withElmJsonProjectVisitor, withReadmeProjectVisitor, withDirectDependenciesProjectVisitor, withDependenciesProjectVisitor, withFinalProjectEvaluation, withExtraFilesProjectVisitor, withContextFromImportedModules
@docs providesFixesForProjectRule
@ -309,10 +309,10 @@ import Elm.Syntax.Node as Node exposing (Node(..))
import Elm.Syntax.Pattern exposing (Pattern)
import Elm.Syntax.Range as Range exposing (Range)
import Json.Encode as Encode
import Review.Cache.ArbitraryFile as ArbitraryFile
import Review.Cache.ContentHash exposing (ContentHash)
import Review.Cache.ContextHash as ContextHash exposing (ComparableContextHash, ContextHash)
import Review.Cache.EndAnalysis as EndAnalysisCache
import Review.Cache.ExtraFile as ExtraFile
import Review.Cache.Module as ModuleCache
import Review.Cache.ProjectFile as ProjectFileCache
import Review.ElmProjectEncoder
@ -397,15 +397,15 @@ type alias ModuleRuleSchemaData moduleContext =
-- Project visitors
, elmJsonVisitor : Maybe (Maybe Elm.Project.Project -> moduleContext -> moduleContext)
, arbitraryFilesVisitor : Maybe (List { path : String, content : String } -> moduleContext -> moduleContext)
, arbitraryFileRequest : ArbitraryFileRequest
, extraFilesVisitor : Maybe (List { path : String, content : String } -> moduleContext -> moduleContext)
, extraFileRequest : ExtraFileRequest
, 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 =
type alias ExtraFileRequest =
List String
@ -1036,8 +1036,8 @@ newModuleRuleSchema name initialModuleContext =
, caseBranchVisitorOnExit = Nothing
, finalEvaluationFn = Nothing
, elmJsonVisitor = Nothing
, arbitraryFilesVisitor = Nothing
, arbitraryFileRequest = []
, extraFilesVisitor = Nothing
, extraFileRequest = []
, readmeVisitor = Nothing
, dependenciesVisitor = Nothing
, directDependenciesVisitor = Nothing
@ -1105,8 +1105,8 @@ newModuleRuleSchemaUsingContextCreator name moduleContextCreator =
, finalEvaluationFn = Nothing
, elmJsonVisitor = Nothing
, readmeVisitor = Nothing
, arbitraryFilesVisitor = Nothing
, arbitraryFileRequest = []
, extraFilesVisitor = Nothing
, extraFileRequest = []
, dependenciesVisitor = Nothing
, directDependenciesVisitor = Nothing
, providesFixes = False
@ -1124,8 +1124,8 @@ fromModuleRuleSchema ((ModuleRuleSchema schema) as moduleVisitor) =
{ name = schema.name
, initialProjectContext = initialModuleContext
, elmJsonVisitor = compactProjectDataVisitors (Maybe.map .project) schema.elmJsonVisitor
, arbitraryFilesVisitor = compactArbitraryFilesVisitor schema.arbitraryFilesVisitor
, arbitraryFileRequest = schema.arbitraryFileRequest
, extraFilesVisitor = compactExtraFilesVisitor schema.extraFilesVisitor
, extraFileRequest = schema.extraFileRequest
, readmeVisitor = compactProjectDataVisitors (Maybe.map .content) schema.readmeVisitor
, directDependenciesVisitor = compactProjectDataVisitors identity schema.directDependenciesVisitor
, dependenciesVisitor = compactProjectDataVisitors identity schema.dependenciesVisitor
@ -1144,8 +1144,8 @@ fromModuleRuleSchema ((ModuleRuleSchema schema) as moduleVisitor) =
{ name = schema.name
, initialProjectContext = ()
, elmJsonVisitor = Nothing
, arbitraryFilesVisitor = Nothing
, arbitraryFileRequest = []
, extraFilesVisitor = Nothing
, extraFileRequest = []
, readmeVisitor = Nothing
, directDependenciesVisitor = Nothing
, dependenciesVisitor = Nothing
@ -1170,11 +1170,11 @@ compactProjectDataVisitors getData maybeVisitor =
Just (\rawData moduleContext -> ( [], visitor (getData rawData) moduleContext ))
compactArbitraryFilesVisitor : Maybe (List { a | path : String } -> moduleContext -> moduleContext) -> Maybe (List { a | path : String } -> moduleContext -> ( List nothing, moduleContext ))
compactArbitraryFilesVisitor maybeArbitraryFilesVisitor =
case maybeArbitraryFilesVisitor of
Just arbitraryFilesVisitor ->
Just (\files moduleContext -> ( [], arbitraryFilesVisitor files moduleContext ))
compactExtraFilesVisitor : Maybe (List { a | path : String } -> moduleContext -> moduleContext) -> Maybe (List { a | path : String } -> moduleContext -> ( List nothing, moduleContext ))
compactExtraFilesVisitor maybeExtraFilesVisitor =
case maybeExtraFilesVisitor of
Just extraFilesVisitor ->
Just (\files moduleContext -> ( [], extraFilesVisitor files moduleContext ))
Nothing ->
Nothing
@ -1203,8 +1203,8 @@ type alias ProjectRuleSchemaData projectContext moduleContext =
{ name : String
, initialProjectContext : projectContext
, elmJsonVisitor : Maybe (Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> projectContext -> ( List (Error {}), projectContext ))
, arbitraryFilesVisitor : Maybe (List { path : String, content : String } -> projectContext -> ( List (Error {}), projectContext ))
, arbitraryFileRequest : ArbitraryFileRequest
, extraFilesVisitor : Maybe (List { path : String, content : String } -> projectContext -> ( List (Error {}), projectContext ))
, extraFileRequest : ExtraFileRequest
, readmeVisitor : Maybe (Maybe { readmeKey : ReadmeKey, content : String } -> projectContext -> ( List (Error {}), projectContext ))
, directDependenciesVisitor : Maybe (Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List (Error {}), projectContext ))
, dependenciesVisitor : Maybe (Dict String Review.Project.Dependency.Dependency -> projectContext -> ( List (Error {}), projectContext ))
@ -1265,8 +1265,8 @@ newProjectRuleSchema name initialProjectContext =
{ name = name
, initialProjectContext = initialProjectContext
, elmJsonVisitor = Nothing
, arbitraryFilesVisitor = Nothing
, arbitraryFileRequest = []
, extraFilesVisitor = Nothing
, extraFileRequest = []
, readmeVisitor = Nothing
, directDependenciesVisitor = Nothing
, dependenciesVisitor = Nothing
@ -1292,7 +1292,7 @@ fromProjectRuleSchema (ProjectRuleSchema schema) =
RequestedData.combine
(Maybe.map requestedDataFromContextCreator schema.moduleContextCreator)
(Maybe.map (.fromModuleToProject >> requestedDataFromContextCreator) schema.folder)
|> RequestedData.withFiles schema.arbitraryFileRequest
|> RequestedData.withFiles schema.extraFileRequest
, providesFixes = schema.providesFixes
, ruleProjectVisitor =
Ok
@ -1319,7 +1319,7 @@ removeUnknownModulesFromInitialCache validProject projectRuleCache =
emptyCache : ProjectRuleCache projectContext
emptyCache =
{ elmJson = Nothing
, arbitraryFiles = Nothing
, extraFiles = Nothing
, readme = Nothing
, dependencies = Nothing
, moduleContexts = Dict.empty
@ -1406,8 +1406,8 @@ mergeModuleVisitorsHelp ruleName_ initialProjectContext moduleContextCreator vis
, finalEvaluationFn = Nothing
, elmJsonVisitor = Nothing
, readmeVisitor = Nothing
, arbitraryFilesVisitor = Nothing
, arbitraryFileRequest = []
, extraFilesVisitor = Nothing
, extraFileRequest = []
, dependenciesVisitor = Nothing
, directDependenciesVisitor = Nothing
, providesFixes = False
@ -1863,12 +1863,12 @@ withElmJsonProjectVisitor visitor (ProjectRuleSchema schema) =
{-| REPLACEME
-}
withArbitraryFilesProjectVisitor :
ArbitraryFileRequest
withExtraFilesProjectVisitor :
ExtraFileRequest
-> (List { path : String, content : String } -> projectContext -> ( List (Error { useErrorForModule : () }), projectContext ))
-> ProjectRuleSchema schemaState projectContext moduleContext
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
withArbitraryFilesProjectVisitor requestedFiles baseVisitor (ProjectRuleSchema schema) =
withExtraFilesProjectVisitor requestedFiles baseVisitor (ProjectRuleSchema schema) =
let
visitor : List { path : String, content : String } -> projectContext -> ( List (Error {}), projectContext )
visitor files context =
@ -1877,8 +1877,8 @@ withArbitraryFilesProjectVisitor requestedFiles baseVisitor (ProjectRuleSchema s
in
ProjectRuleSchema
{ schema
| arbitraryFilesVisitor = Just (combineVisitors visitor schema.arbitraryFilesVisitor)
, arbitraryFileRequest = requestedFiles ++ schema.arbitraryFileRequest
| extraFilesVisitor = Just (combineVisitors visitor schema.extraFilesVisitor)
, extraFileRequest = requestedFiles ++ schema.extraFileRequest
}
@ -2354,12 +2354,12 @@ withElmJsonModuleVisitor visitor (ModuleRuleSchema schema) =
{-| Add a visitor to the [`ModuleRuleSchema`](#ModuleRuleSchema) which will visit
the project's `README.md` file.
-}
withArbitraryFilesModuleVisitor :
ArbitraryFileRequest
withExtraFilesModuleVisitor :
ExtraFileRequest
-> (List { path : String, content : String } -> moduleContext -> moduleContext)
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
withArbitraryFilesModuleVisitor requestedFiles baseVisitor (ModuleRuleSchema schema) =
withExtraFilesModuleVisitor requestedFiles baseVisitor (ModuleRuleSchema schema) =
let
visitor : List { path : String, content : String } -> moduleContext -> moduleContext
visitor files context =
@ -2368,8 +2368,8 @@ withArbitraryFilesModuleVisitor requestedFiles baseVisitor (ModuleRuleSchema sch
in
ModuleRuleSchema
{ schema
| arbitraryFilesVisitor = Just (combineContextOnlyVisitor visitor schema.arbitraryFilesVisitor)
, arbitraryFileRequest = requestedFiles ++ schema.arbitraryFileRequest
| extraFilesVisitor = Just (combineContextOnlyVisitor visitor schema.extraFilesVisitor)
, extraFileRequest = requestedFiles ++ schema.extraFileRequest
}
@ -4261,8 +4261,8 @@ type alias ProjectFileCache projectContext =
ProjectFileCache.Entry (Error {}) projectContext
type alias ArbitraryFilesCache projectContext =
ArbitraryFile.Entry (Error {}) projectContext
type alias ExtraFilesCache projectContext =
ExtraFile.Entry (Error {}) projectContext
type alias FinalProjectEvaluationCache projectContext =
@ -4393,7 +4393,7 @@ errorsFromCache cache =
List.concat
[ Dict.foldl (\_ cacheEntry acc -> List.append (ModuleCache.errors cacheEntry) acc) [] cache.moduleContexts
, ProjectFileCache.errorsForMaybe cache.elmJson
, ArbitraryFile.errorsForMaybe cache.arbitraryFiles
, ExtraFile.errorsForMaybe cache.extraFiles
, ProjectFileCache.errorsForMaybe cache.readme
, ProjectFileCache.errorsForMaybe cache.dependencies
, Maybe.map EndAnalysisCache.output cache.finalEvaluationErrors |> Maybe.withDefault []
@ -4406,7 +4406,7 @@ errorsFromCache cache =
type alias ProjectRuleCache projectContext =
{ elmJson : Maybe (ProjectFileCache projectContext)
, arbitraryFiles : Maybe (ArbitraryFilesCache projectContext)
, extraFiles : Maybe (ExtraFilesCache projectContext)
, readme : Maybe (ProjectFileCache projectContext)
, dependencies : Maybe (ProjectFileCache projectContext)
, moduleContexts : Dict String (ModuleCacheEntry projectContext)
@ -4437,15 +4437,15 @@ computeStepsForProject reviewOptions { project, ruleProjectVisitors, fixedErrors
reviewOptions
(computeElmJson reviewOptions project fixedErrors elmJsonData ruleProjectVisitors [])
ArbitraryFiles ->
ExtraFiles ->
let
arbitraryFiles : List { path : String, content : String }
arbitraryFiles =
ValidProject.arbitraryFiles project
extraFiles : List { path : String, content : String }
extraFiles =
ValidProject.extraFiles project
in
computeStepsForProject
reviewOptions
(computeArbitraryFiles reviewOptions project fixedErrors arbitraryFiles ruleProjectVisitors [])
(computeExtraFiles reviewOptions project fixedErrors extraFiles ruleProjectVisitors [])
Readme ->
let
@ -4500,7 +4500,7 @@ computeStepsForProject reviewOptions { project, ruleProjectVisitors, fixedErrors
type Step
= ElmJson
| ArbitraryFiles
| ExtraFiles
| Readme
| Dependencies
| Modules (Zipper GraphModule)
@ -4510,7 +4510,7 @@ type Step
type StepToComputeContext
= ElmJsonStep
| ArbitraryFilesStep
| ExtraFilesStep
| ReadmeStep
| DependenciesStep
| AfterProjectFilesStep
@ -4535,7 +4535,7 @@ computeElmJson reviewOptions project fixedErrors elmJsonData remainingRules accR
case remainingRules of
[] ->
{ project = project
, step = ArbitraryFiles
, step = ExtraFiles
, ruleProjectVisitors = accRules
, fixedErrors = fixedErrors
}
@ -4574,7 +4574,7 @@ computeElmJson reviewOptions project fixedErrors elmJsonData remainingRules accR
(untouched :: accRules)
computeArbitraryFiles :
computeExtraFiles :
ReviewOptionsData
-> ValidProject
-> FixedErrors
@ -4582,7 +4582,7 @@ computeArbitraryFiles :
-> List RuleProjectVisitor
-> List RuleProjectVisitor
-> { project : ValidProject, ruleProjectVisitors : List RuleProjectVisitor, step : Step, fixedErrors : FixedErrors }
computeArbitraryFiles reviewOptions project fixedErrors arbitraryFiles remainingRules accRules =
computeExtraFiles reviewOptions project fixedErrors extraFiles remainingRules accRules =
case remainingRules of
[] ->
{ project = project
@ -4592,13 +4592,13 @@ computeArbitraryFiles reviewOptions project fixedErrors arbitraryFiles remaining
}
((RuleProjectVisitor rule) as untouched) :: rest ->
case rule.arbitraryFilesVisitor of
case rule.extraFilesVisitor of
Just visitor ->
let
( errors, RuleProjectVisitor updatedRule ) =
visitor project arbitraryFiles
visitor project extraFiles
in
case standardFindFix reviewOptions project fixedErrors updatedRule.setErrorsForArbitraryFiles errors of
case standardFindFix reviewOptions project fixedErrors updatedRule.setErrorsForExtraFiles errors of
FoundFixStandard { newProject, newRule, newFixedErrors, step } ->
{ project = newProject
, ruleProjectVisitors = newRule :: (rest ++ accRules)
@ -4607,20 +4607,20 @@ computeArbitraryFiles reviewOptions project fixedErrors arbitraryFiles remaining
}
FoundNoFixesStandard newRule ->
computeArbitraryFiles
computeExtraFiles
reviewOptions
project
fixedErrors
arbitraryFiles
extraFiles
rest
(newRule :: accRules)
Nothing ->
computeArbitraryFiles
computeExtraFiles
reviewOptions
project
fixedErrors
arbitraryFiles
extraFiles
rest
(untouched :: accRules)
@ -5590,7 +5590,7 @@ The hidden state is `{ cache : ProjectRuleCache projectContext, ruleData : Chang
type alias RuleProjectVisitorOperations =
{ elmJsonVisitor : Maybe (ValidProject -> Maybe { elmJsonKey : ElmJsonKey, project : Elm.Project.Project } -> ( List (Error {}), RuleProjectVisitor ))
, readmeVisitor : Maybe (ValidProject -> Maybe { readmeKey : ReadmeKey, content : String } -> ( List (Error {}), RuleProjectVisitor ))
, arbitraryFilesVisitor : Maybe (ValidProject -> List { path : String, content : String } -> ( List (Error {}), RuleProjectVisitor ))
, extraFilesVisitor : Maybe (ValidProject -> List { path : String, content : String } -> ( List (Error {}), RuleProjectVisitor ))
, dependenciesVisitor : Maybe (ValidProject -> { all : Dict String Review.Project.Dependency.Dependency, direct : Dict String Review.Project.Dependency.Dependency } -> ( List (Error {}), RuleProjectVisitor ))
, createModuleVisitorFromProjectVisitor : Maybe (ValidProject -> String -> ContentHash -> Graph.Adjacency () -> Maybe (AvailableData -> RuleModuleVisitor))
, finalProjectEvaluation : Maybe (() -> ( List (Error {}), RuleProjectVisitor ))
@ -5599,7 +5599,7 @@ type alias RuleProjectVisitorOperations =
, getErrors : () -> List (Error {})
, setErrorsForModule : String -> List (Error {}) -> RuleProjectVisitor
, setErrorsForElmJson : List (Error {}) -> RuleProjectVisitor
, setErrorsForArbitraryFiles : List (Error {}) -> RuleProjectVisitor
, setErrorsForExtraFiles : List (Error {}) -> RuleProjectVisitor
, setErrorsForReadme : List (Error {}) -> RuleProjectVisitor
, setErrorsForDependencies : List (Error {}) -> RuleProjectVisitor
, setErrorsForFinalEvaluation : List (Error {}) -> RuleProjectVisitor
@ -5620,7 +5620,7 @@ createRuleProjectVisitor schema initialProject ruleData initialCache =
in
RuleProjectVisitor
{ elmJsonVisitor = createProjectVisitor schema hidden schema.elmJsonVisitor ElmJsonStep ValidProject.elmJsonHash .elmJson (\entry -> raiseCache { cache | elmJson = Just entry }) (\() -> raise hidden)
, arbitraryFilesVisitor = createArbitraryFilesVisitor schema hidden schema.arbitraryFilesVisitor ArbitraryFilesStep (\entry -> raiseCache { cache | arbitraryFiles = Just entry }) (\() -> raise hidden)
, extraFilesVisitor = createExtraFilesVisitor schema hidden schema.extraFilesVisitor ExtraFilesStep (\entry -> raiseCache { cache | extraFiles = Just entry }) (\() -> raise hidden)
, readmeVisitor = createProjectVisitor schema hidden schema.readmeVisitor ReadmeStep ValidProject.readmeHash .readme (\entry -> raiseCache { cache | readme = Just entry }) (\() -> raise hidden)
, dependenciesVisitor = createDependenciesVisitor schema hidden.ruleData raiseCache cache { allVisitor = schema.dependenciesVisitor, directVisitor = schema.directDependenciesVisitor }
, createModuleVisitorFromProjectVisitor = createModuleVisitorFromProjectVisitor schema raiseCache hidden
@ -5630,7 +5630,7 @@ createRuleProjectVisitor schema initialProject ruleData initialCache =
, getErrors = \() -> errorsFromCache (finalCacheMarker schema.name hidden.ruleData.ruleId cache)
, setErrorsForModule = \filePath newErrors -> raiseCache { cache | moduleContexts = Dict.update filePath (Maybe.map (\entry -> ModuleCache.setErrors newErrors entry)) cache.moduleContexts }
, setErrorsForElmJson = \newErrors -> raiseCache { cache | elmJson = ProjectFileCache.setErrors newErrors cache.elmJson }
, setErrorsForArbitraryFiles = \newErrors -> raiseCache { cache | arbitraryFiles = ArbitraryFile.setErrors newErrors cache.arbitraryFiles }
, setErrorsForExtraFiles = \newErrors -> raiseCache { cache | extraFiles = ExtraFile.setErrors newErrors cache.extraFiles }
, setErrorsForReadme = \newErrors -> raiseCache { cache | readme = ProjectFileCache.setErrors newErrors cache.readme }
, setErrorsForDependencies = \newErrors -> raiseCache { cache | dependencies = ProjectFileCache.setErrors newErrors cache.dependencies }
, setErrorsForFinalEvaluation = \newErrors -> raiseCache { cache | finalEvaluationErrors = EndAnalysisCache.setOutput newErrors cache.finalEvaluationErrors }
@ -5717,12 +5717,12 @@ createProjectVisitor schema hidden maybeVisitor step computeContentHash cacheGet
)
createArbitraryFilesVisitor :
createExtraFilesVisitor :
ProjectRuleSchemaData projectContext moduleContext
-> RuleProjectVisitorHidden projectContext
-> Maybe (data -> projectContext -> ( List (Error {}), projectContext ))
-> StepToComputeContext
-> (ArbitraryFilesCache projectContext -> RuleProjectVisitor)
-> (ExtraFilesCache projectContext -> RuleProjectVisitor)
-> (() -> RuleProjectVisitor)
->
Maybe
@ -5730,7 +5730,7 @@ createArbitraryFilesVisitor :
-> data
-> ( List (Error {}), RuleProjectVisitor )
)
createArbitraryFilesVisitor schema hidden maybeVisitor step toRuleProjectVisitor toRuleProjectVisitorWithoutChangingCache =
createExtraFilesVisitor schema hidden maybeVisitor step toRuleProjectVisitor toRuleProjectVisitorWithoutChangingCache =
case maybeVisitor of
Nothing ->
Nothing
@ -5748,15 +5748,15 @@ createArbitraryFilesVisitor schema hidden maybeVisitor step toRuleProjectVisitor
contentHashes : List ContentHash
contentHashes =
ValidProject.arbitraryFilesHash project
ValidProject.extraFilesHash project
cachePredicate : ArbitraryFilesCache projectContext -> Bool
cachePredicate arbitraryFiles =
ArbitraryFile.match contentHashes inputContextHash arbitraryFiles
cachePredicate : ExtraFilesCache projectContext -> Bool
cachePredicate extraFiles =
ExtraFile.match contentHashes inputContextHash extraFiles
in
case reuseProjectRuleCache cachePredicate .arbitraryFiles hidden.cache of
case reuseProjectRuleCache cachePredicate .extraFiles hidden.cache of
Just entry ->
( ArbitraryFile.errors entry, toRuleProjectVisitorWithoutChangingCache () )
( ExtraFile.errors entry, toRuleProjectVisitorWithoutChangingCache () )
Nothing ->
let
@ -5768,7 +5768,7 @@ createArbitraryFilesVisitor schema hidden maybeVisitor step toRuleProjectVisitor
filterExceptionsAndSetName hidden.ruleData.exceptions schema.name errorsForVisitor
in
( errors
, ArbitraryFile.create
, ExtraFile.create
{ contentHashes = contentHashes
, errors = errors
, inputContextHash = inputContextHash
@ -5869,7 +5869,7 @@ findInitialInputContext cache step defaultContext =
ElmJsonStep ->
( [], defaultContext )
ArbitraryFilesStep ->
ExtraFilesStep ->
case cache.elmJson of
Just entry ->
( [ ProjectFileCache.outputContextHash entry ], ProjectFileCache.outputContext entry )
@ -5878,12 +5878,12 @@ findInitialInputContext cache step defaultContext =
findInitialInputContext cache ElmJsonStep defaultContext
ReadmeStep ->
case cache.arbitraryFiles of
case cache.extraFiles of
Just entry ->
( [ ArbitraryFile.outputContextHash entry ], ArbitraryFile.outputContext entry )
( [ ExtraFile.outputContextHash entry ], ExtraFile.outputContext entry )
Nothing ->
findInitialInputContext cache ArbitraryFilesStep defaultContext
findInitialInputContext cache ExtraFilesStep defaultContext
DependenciesStep ->
case cache.readme of

View File

@ -1,4 +1,4 @@
module Review.Rule.WithArbitraryFilesVisitorTest exposing (all)
module Review.Rule.WithExtraFilesVisitorTest exposing (all)
import Review.Project as Project exposing (Project)
import Review.Rule as Rule exposing (Error, Rule)
@ -8,7 +8,7 @@ import Test exposing (Test, describe, test)
all : Test
all =
describe "Review.Rule.withArbitraryFilesVisitor"
describe "Review.Rule.withExtraFilesVisitor"
[ test "passes the list of arbitrary files to the rule" <|
\() ->
let
@ -20,7 +20,7 @@ all =
rule : Rule
rule =
createRule (Rule.withArbitraryFilesModuleVisitor [ "foo/some-file.css" ] arbitraryFilesModuleVisitor)
createRule (Rule.withExtraFilesModuleVisitor [ "foo/some-file.css" ] extraFilesModuleVisitor)
in
"""module A exposing (a)
a = 1
@ -44,7 +44,7 @@ a = 1
rule : Rule
rule =
createRule (Rule.withArbitraryFilesModuleVisitor [ "foo/some-file.css" ] arbitraryFilesModuleVisitor)
createRule (Rule.withExtraFilesModuleVisitor [ "foo/some-file.css" ] extraFilesModuleVisitor)
in
"""module A exposing (a)
a = 1
@ -69,8 +69,8 @@ a = 1
rule : Rule
rule =
createRule
(Rule.withArbitraryFilesModuleVisitor [ "a.txt", "c.txt" ] (reportsFileNames "A")
>> Rule.withArbitraryFilesModuleVisitor [ "b.txt" ] (reportsFileNames "B")
(Rule.withExtraFilesModuleVisitor [ "a.txt", "c.txt" ] (reportsFileNames "A")
>> Rule.withExtraFilesModuleVisitor [ "b.txt" ] (reportsFileNames "B")
)
in
"""module A exposing (a)
@ -102,8 +102,8 @@ createRule modifier =
|> Rule.fromModuleRuleSchema
arbitraryFilesModuleVisitor : List { path : String, content : String } -> Context -> Context
arbitraryFilesModuleVisitor files context =
extraFilesModuleVisitor : List { path : String, content : String } -> Context -> Context
extraFilesModuleVisitor files context =
List.map .path files ++ context
@ -122,5 +122,5 @@ finalEvaluation context =
createProject : List { path : String, content : String } -> Project
createProject arbitraryFiles =
Project.addArbitraryFiles arbitraryFiles Project.new
createProject extraFiles =
Project.addExtraFiles extraFiles Project.new