Use direct dependencies visitor in test rules

This commit is contained in:
Jeroen Engels 2022-08-22 19:55:37 +02:00
parent d746a21c9a
commit 2a211e9d22
8 changed files with 19 additions and 20 deletions

View File

@ -5555,7 +5555,7 @@ scopeRule : RunnableProjectVisitor ScopeProjectContext ScopeModuleContext
scopeRule =
newProjectRuleSchema "elm-review__SCOPE" scope_initialProjectContext
|> withContextFromImportedModules
|> withDependenciesProjectVisitor (scope_dependenciesVisitor |> scope_pairWithNoErrors)
|> withDirectDependenciesProjectVisitor (scope_dependenciesVisitor |> scope_pairWithNoErrors)
|> withModuleVisitor scope_moduleVisitor
|> withModuleContext
{ fromProjectToModule = scope_fromProjectToModule

View File

@ -105,7 +105,7 @@ rule configuration =
userConfigurationToStableConfiguration configuration elementPredicate
in
Rule.newProjectRuleSchema "NoDeprecated" initialProjectContext
|> Rule.withDependenciesProjectVisitor (dependenciesVisitor stableConfiguration)
|> Rule.withDirectDependenciesProjectVisitor (dependenciesVisitor stableConfiguration)
|> Rule.withModuleVisitor (moduleVisitor stableConfiguration)
|> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = fromProjectToModule stableConfiguration

View File

@ -89,7 +89,7 @@ rule : Rule
rule =
Rule.newProjectRuleSchema "NoMissingTypeExpose" initialProjectContext
|> Rule.withElmJsonProjectVisitor elmJsonVisitor
|> Rule.withDependenciesProjectVisitor dependencyDictVisitor
|> Rule.withDirectDependenciesProjectVisitor dependencyDictVisitor
|> Rule.withModuleVisitor moduleVisitor
|> Rule.withContextFromImportedModules
|> Rule.withModuleContextUsingContextCreator

View File

@ -44,7 +44,7 @@ rule : Rule
rule =
Rule.newProjectRuleSchema "NoUnused.Dependencies" initialProjectContext
|> Rule.withElmJsonProjectVisitor elmJsonVisitor
|> Rule.withDependenciesProjectVisitor dependenciesVisitor
|> Rule.withDirectDependenciesProjectVisitor dependenciesVisitor
|> Rule.withModuleVisitor moduleVisitor
|> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = fromProjectToModule
@ -66,18 +66,15 @@ dependenciesVisitor dependencies projectContext =
let
moduleNameToDependency : Dict String String
moduleNameToDependency =
dependencies
|> Dict.filter
(\packageName _ ->
Set.member packageName projectContext.directProjectDependencies
|| Set.member packageName projectContext.directTestDependencies
)
|> Dict.toList
|> List.concatMap
(\( packageName, dependency ) ->
List.map (\{ name } -> ( name, packageName )) (Dependency.modules dependency)
)
|> Dict.fromList
Dict.foldl
(\packageName dependency dict ->
List.foldl
(\{ name } d -> Dict.insert name packageName d)
dict
(Dependency.modules dependency)
)
Dict.empty
dependencies
in
( []
, { projectContext

View File

@ -7,12 +7,13 @@ import NoUnused.Dependencies exposing (rule)
import Review.Project as Project exposing (Project)
import Review.Project.Dependency as Dependency exposing (Dependency)
import Review.Test
import Review.Test.Dependencies
import Test exposing (Test, describe, test)
createProject : Maybe String -> String -> Project
createProject maybeTestModule rawElmJson =
Project.new
Review.Test.Dependencies.projectWithElmCore
|> Project.addElmJson (createElmJson rawElmJson)
|> Project.addDependency packageWithBar
|> Project.addDependency packageWithFoo

View File

@ -102,7 +102,7 @@ rule : Rule
rule =
Rule.newProjectRuleSchema "NoUnused.Variables" initialContext
|> Rule.withElmJsonProjectVisitor (\project context -> ( [], elmJsonVisitor project context ))
|> Rule.withDependenciesProjectVisitor dependenciesVisitor
|> Rule.withDirectDependenciesProjectVisitor dependenciesVisitor
|> Rule.withModuleVisitor moduleVisitor
|> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = fromProjectToModule

View File

@ -2585,7 +2585,8 @@ rawPackageElmJson =
],
"elm-version": "0.19.0 <= v < 0.20.0",
"dependencies": {
"package/author": "1.0.0 <= v < 2.0.0"
"package/author": "1.0.0 <= v < 2.0.0",
"author/package-with-foo": "1.0.0 <= v < 2.0.0"
},
"test-dependencies": {}
}"""

View File

@ -572,7 +572,7 @@ rule (Configuration config) =
Set.fromList typeNamesList
in
Rule.newProjectRuleSchema "Simplify" initialContext
|> Rule.withDependenciesProjectVisitor (dependenciesVisitor typeNames)
|> Rule.withDirectDependenciesProjectVisitor (dependenciesVisitor typeNames)
|> Rule.withModuleVisitor (moduleVisitor typeNames)
|> Rule.withModuleContextUsingContextCreator
{ fromProjectToModule = fromProjectToModule