mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-10-26 16:10:55 +03:00
Support excluding folders
This commit is contained in:
parent
56e75c931f
commit
abb2dce7a7
@ -1,6 +1,7 @@
|
||||
module Review.FilePattern exposing (FilePattern, exclude, excludeFolder, include, match)
|
||||
|
||||
import Glob exposing (Glob)
|
||||
import Review.Rule exposing (globalError)
|
||||
|
||||
|
||||
type FilePattern
|
||||
@ -32,7 +33,7 @@ exclude globStr =
|
||||
|
||||
excludeFolder : String -> FilePattern
|
||||
excludeFolder globStr =
|
||||
case Glob.fromString globStr of
|
||||
case Glob.fromString (toFolder globStr) of
|
||||
Ok glob ->
|
||||
ExcludeFolder glob
|
||||
|
||||
@ -40,6 +41,15 @@ excludeFolder globStr =
|
||||
InvalidGlob globStr
|
||||
|
||||
|
||||
toFolder : String -> String
|
||||
toFolder globStr =
|
||||
if String.endsWith "/" globStr then
|
||||
globStr ++ "**/*"
|
||||
|
||||
else
|
||||
globStr ++ "/**/*"
|
||||
|
||||
|
||||
match : List FilePattern -> String -> Bool
|
||||
match filePatterns str =
|
||||
matchHelp filePatterns str False
|
||||
@ -52,7 +62,17 @@ matchHelp filePatterns str acc =
|
||||
acc
|
||||
|
||||
(Include glob) :: rest ->
|
||||
matchHelp rest str (Glob.match glob str)
|
||||
matchHelp rest str (acc || Glob.match glob str)
|
||||
|
||||
(Exclude glob) :: rest ->
|
||||
matchHelp rest str (acc && not (Glob.match glob str))
|
||||
|
||||
(ExcludeFolder glob) :: rest ->
|
||||
if Glob.match glob str then
|
||||
False
|
||||
|
||||
else
|
||||
matchHelp rest str acc
|
||||
|
||||
_ ->
|
||||
False
|
||||
|
@ -55,5 +55,21 @@ all =
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
|> Expect.equal True
|
||||
, test "should return False when excluding the folder even when re-including the target file" <|
|
||||
\() ->
|
||||
FilePattern.match
|
||||
[ FilePattern.excludeFolder "some"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
|> Expect.equal False
|
||||
, test "should return False when excluding the folder (with trailing /) even when re-including the target file" <|
|
||||
\() ->
|
||||
FilePattern.match
|
||||
[ FilePattern.excludeFolder "some/"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
|> Expect.equal False
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user