mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-08-16 19:40:22 +03:00
Filter out files that were not requested
This commit is contained in:
parent
dddff57491
commit
c9d4a1a5e5
@ -1114,7 +1114,7 @@ fromModuleRuleSchema ((ModuleRuleSchema schema) as moduleVisitor) =
|
||||
{ name = schema.name
|
||||
, initialProjectContext = initialModuleContext
|
||||
, elmJsonVisitor = compactProjectDataVisitors (Maybe.map .project) schema.elmJsonVisitor
|
||||
, arbitraryFilesVisitor = compactProjectDataVisitors identity (Maybe.map Tuple.first schema.arbitraryFilesVisitor)
|
||||
, arbitraryFilesVisitor = compactArbitraryFilesVisitor schema.arbitraryFilesVisitor
|
||||
, arbitraryFileRequest = Maybe.map Tuple.second schema.arbitraryFilesVisitor |> Maybe.withDefault []
|
||||
, readmeVisitor = compactProjectDataVisitors (Maybe.map .content) schema.readmeVisitor
|
||||
, directDependenciesVisitor = compactProjectDataVisitors identity schema.directDependenciesVisitor
|
||||
@ -1160,6 +1160,21 @@ compactProjectDataVisitors getData maybeVisitor =
|
||||
Just (\rawData moduleContext -> ( [], visitor (getData rawData) moduleContext ))
|
||||
|
||||
|
||||
compactArbitraryFilesVisitor : Maybe ( List { a | path : String } -> moduleContext -> moduleContext, List String ) -> Maybe (List { a | path : String } -> moduleContext -> ( List nothing, moduleContext ))
|
||||
compactArbitraryFilesVisitor maybeArbitraryFilesVisitor =
|
||||
case maybeArbitraryFilesVisitor of
|
||||
Just ( arbitraryFilesVisitor, requestedFiles ) ->
|
||||
let
|
||||
predicate : { a | path : String } -> Bool
|
||||
predicate file =
|
||||
List.member file.path requestedFiles
|
||||
in
|
||||
Just (\files moduleContext -> ( [], arbitraryFilesVisitor (List.filter predicate files) moduleContext ))
|
||||
|
||||
Nothing ->
|
||||
Nothing
|
||||
|
||||
|
||||
|
||||
-- PROJECT RULES
|
||||
|
||||
|
@ -19,6 +19,25 @@ all =
|
||||
in
|
||||
"""module A exposing (a)
|
||||
a = 1
|
||||
"""
|
||||
|> Review.Test.runWithProjectData (Project.addArbitraryFiles arbitraryFiles Project.new) rule
|
||||
|> Review.Test.expectGlobalErrors
|
||||
[ { message = "Found these files"
|
||||
, details = [ "foo/some-file.css" ]
|
||||
}
|
||||
]
|
||||
, test "filters out files that were not requested" <|
|
||||
\() ->
|
||||
let
|
||||
arbitraryFiles : List { path : String, content : String }
|
||||
arbitraryFiles =
|
||||
[ { path = "foo/some-file.css", content = "#thing { color: red; }" }
|
||||
, { path = "foo/some-other-file.css", content = "#thing { color: red; }" }
|
||||
, { path = "bar/some-file.css", content = "#thing { color: red; }" }
|
||||
]
|
||||
in
|
||||
"""module A exposing (a)
|
||||
a = 1
|
||||
"""
|
||||
|> Review.Test.runWithProjectData (Project.addArbitraryFiles arbitraryFiles Project.new) rule
|
||||
|> Review.Test.expectGlobalErrors
|
||||
|
Loading…
Reference in New Issue
Block a user