mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-11-25 10:04:38 +03:00
Add includeByDefault to FilePattern.match
This commit is contained in:
parent
71cfd6187d
commit
ec5ab00113
@ -293,31 +293,31 @@ toDirectory globStr =
|
||||
|
||||
{-| REPLACEME
|
||||
-}
|
||||
match : Summary -> String -> Bool
|
||||
match (Summary summary) str =
|
||||
match : { includeByDefault : Bool } -> Summary -> String -> Bool
|
||||
match { includeByDefault } (Summary summary) str =
|
||||
if List.any (\dirGlob -> Glob.match dirGlob str) summary.excludedDirectories then
|
||||
False
|
||||
|
||||
else
|
||||
matchHelp summary.includeExclude str
|
||||
matchHelp includeByDefault summary.includeExclude str
|
||||
|
||||
|
||||
matchHelp : List CompactFilePattern -> String -> Bool
|
||||
matchHelp filePatterns str =
|
||||
matchHelp : Bool -> List CompactFilePattern -> String -> Bool
|
||||
matchHelp includeByDefault filePatterns str =
|
||||
case filePatterns of
|
||||
[] ->
|
||||
False
|
||||
includeByDefault
|
||||
|
||||
(CompactInclude globs) :: rest ->
|
||||
if List.any (\glob -> Glob.match glob str) globs then
|
||||
True
|
||||
|
||||
else
|
||||
matchHelp rest str
|
||||
matchHelp includeByDefault rest str
|
||||
|
||||
(CompactExclude globs) :: rest ->
|
||||
if List.any (\glob -> Glob.match glob str) globs then
|
||||
False
|
||||
|
||||
else
|
||||
matchHelp rest str
|
||||
matchHelp includeByDefault rest str
|
||||
|
@ -2028,7 +2028,7 @@ withExtraFilesProjectVisitor baseVisitor filePatterns (ProjectRuleSchema schema)
|
||||
let
|
||||
visitor : ExtraFileData -> projectContext -> ( List (Error {}), projectContext )
|
||||
visitor files context =
|
||||
baseVisitor (Dict.filter (\path _ -> FilePattern.match filePatternSummary path) files.withFileKeys) context
|
||||
baseVisitor (Dict.filter (\path _ -> FilePattern.match { includeByDefault = False } filePatternSummary path) files.withFileKeys) context
|
||||
|> Tuple.mapFirst removeErrorPhantomTypes
|
||||
in
|
||||
ProjectRuleSchema
|
||||
@ -2582,7 +2582,7 @@ withExtraFilesModuleVisitor baseVisitor filePatterns (ModuleRuleSchema schema) =
|
||||
let
|
||||
visitor : ExtraFileData -> moduleContext -> moduleContext
|
||||
visitor files context =
|
||||
baseVisitor (Dict.filter (\path _ -> FilePattern.match filePatternSummary path) files.withoutFileKeys) context
|
||||
baseVisitor (Dict.filter (\path _ -> FilePattern.match { includeByDefault = False } filePatternSummary path) files.withoutFileKeys) context
|
||||
in
|
||||
ModuleRuleSchema
|
||||
{ schema
|
||||
|
@ -17,13 +17,24 @@ all =
|
||||
matchTest : Test
|
||||
matchTest =
|
||||
describe "match"
|
||||
[ test "should return False when the list is empty" <|
|
||||
[ test "should return False when the list is empty and includeByDefault is False" <|
|
||||
\() ->
|
||||
matchAgainst [] "some/file/path.ext"
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[]
|
||||
"some/file/path.ext"
|
||||
|> Expect.equal False
|
||||
, test "should return True when the list is empty and includeByDefault is True" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = True }
|
||||
[]
|
||||
"some/file/path.ext"
|
||||
|> Expect.equal True
|
||||
, test "should return True when including the target file" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
@ -31,6 +42,7 @@ matchTest =
|
||||
, test "should return True when including through *" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/**/*"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
@ -38,6 +50,7 @@ matchTest =
|
||||
, test "should return True when including through * with an extension" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/**/*.ext"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
@ -45,6 +58,7 @@ matchTest =
|
||||
, test "should return True when including through **/*" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/**/*"
|
||||
]
|
||||
"some/file/path.ext"
|
||||
@ -52,6 +66,7 @@ matchTest =
|
||||
, test "should return False when including through **/* but excluding the target file" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/**/*"
|
||||
, FilePattern.exclude "some/file/path.ext"
|
||||
]
|
||||
@ -60,6 +75,7 @@ matchTest =
|
||||
, test "should return True when excluding through **/* but re-including the target file" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.exclude "some/file/**/*"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
@ -68,6 +84,7 @@ matchTest =
|
||||
, test "should return True when including then excluding then including again" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.include "some/file/**/*"
|
||||
, FilePattern.exclude "some/file/path.*"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
@ -77,6 +94,7 @@ matchTest =
|
||||
, test "should return False when including then excluding then including again" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.exclude "some/file/**/*"
|
||||
, FilePattern.include "some/file/path.*"
|
||||
, FilePattern.exclude "some/file/path.ext"
|
||||
@ -86,6 +104,7 @@ matchTest =
|
||||
, test "should return False when excluding the folder even when re-including the target file" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.excludeDirectory "some"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
@ -94,6 +113,7 @@ matchTest =
|
||||
, test "should return False when excluding the folder (with trailing /) even when re-including the target file" <|
|
||||
\() ->
|
||||
matchAgainst
|
||||
{ includeByDefault = False }
|
||||
[ FilePattern.excludeDirectory "some/"
|
||||
, FilePattern.include "some/file/path.ext"
|
||||
]
|
||||
@ -102,11 +122,11 @@ matchTest =
|
||||
]
|
||||
|
||||
|
||||
matchAgainst : List FilePattern -> String -> Bool
|
||||
matchAgainst filePatterns str =
|
||||
matchAgainst : { includeByDefault : Bool } -> List FilePattern -> String -> Bool
|
||||
matchAgainst includeByDefault filePatterns str =
|
||||
case FilePattern.compact filePatterns of
|
||||
Ok filePatternCompact ->
|
||||
FilePattern.match filePatternCompact str
|
||||
FilePattern.match includeByDefault filePatternCompact str
|
||||
|
||||
Err globs ->
|
||||
Debug.todo ("Invalid globs:\n" ++ String.join "\n" globs)
|
||||
|
Loading…
Reference in New Issue
Block a user