mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-29 01:24:35 +03:00
Filter out files that were not requested
This commit is contained in:
parent
08647ec79d
commit
3816ab1074
@ -1110,7 +1110,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
|
||||
@ -1156,6 +1156,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