mirror of
https://github.com/jfmengels/elm-review.git
synced 2024-08-16 19:40:22 +03:00
Use FilePattern when requesting files
This commit is contained in:
parent
038819ae49
commit
45842b2234
@ -6,7 +6,7 @@ type RequestedData
|
||||
{ moduleNameLookupTable : Bool
|
||||
, sourceCodeExtractor : Bool
|
||||
, ignoredFiles : Bool
|
||||
, files : List String
|
||||
, files : List { files : List { string : String, included : Bool }, excludedFolders : List String }
|
||||
}
|
||||
|
||||
|
||||
@ -35,7 +35,7 @@ combine maybeA maybeB =
|
||||
a
|
||||
|
||||
|
||||
withFiles : List String -> RequestedData -> RequestedData
|
||||
withFiles : List { files : List { string : String, included : Bool }, excludedFolders : List String } -> RequestedData -> RequestedData
|
||||
withFiles files ((RequestedData requested) as untouched) =
|
||||
if List.isEmpty files then
|
||||
untouched
|
||||
|
@ -326,6 +326,7 @@ import Review.ElmProjectEncoder
|
||||
import Review.Error exposing (InternalError)
|
||||
import Review.Exceptions as Exceptions exposing (Exceptions)
|
||||
import Review.FilePath exposing (FilePath)
|
||||
import Review.FilePattern as FilePattern exposing (FilePattern)
|
||||
import Review.Fix as Fix exposing (Fix, FixResult(..))
|
||||
import Review.Fix.FixProblem as FixProblem
|
||||
import Review.Fix.FixedErrors as FixedErrors exposing (FixedErrors)
|
||||
@ -414,7 +415,7 @@ type alias ModuleRuleSchemaData moduleContext =
|
||||
|
||||
|
||||
type alias ExtraFileRequest =
|
||||
Result (List String) (List StringableGlob)
|
||||
Result (List String) (List { files : List { string : String, included : Bool }, excludedFolders : List String })
|
||||
|
||||
|
||||
type alias StringableGlob =
|
||||
@ -893,7 +894,7 @@ ruleKnowsAboutIgnoredFiles (Rule rule) =
|
||||
|
||||
{-| REPLACEME
|
||||
-}
|
||||
ruleRequestedFiles : Rule -> List String
|
||||
ruleRequestedFiles : Rule -> List { files : List { string : String, included : Bool }, excludedFolders : List String }
|
||||
ruleRequestedFiles (Rule rule) =
|
||||
let
|
||||
(RequestedData requestedData) =
|
||||
@ -1314,7 +1315,7 @@ fromProjectRuleSchema (ProjectRuleSchema schema) =
|
||||
(Maybe.map requestedDataFromContextCreator schema.moduleContextCreator)
|
||||
(Maybe.map (.fromModuleToProject >> requestedDataFromContextCreator) schema.folder)
|
||||
-- TODO Keep the original globs as strings and pass them here
|
||||
|> RequestedData.withFiles (List.map .string extraFileGlobs)
|
||||
|> RequestedData.withFiles extraFileGlobs
|
||||
, providesFixes = schema.providesFixes
|
||||
, ruleProjectVisitor =
|
||||
Ok
|
||||
@ -1907,21 +1908,17 @@ withReadmeProjectVisitor visitor (ProjectRuleSchema schema) =
|
||||
{-| REPLACEME
|
||||
-}
|
||||
withExtraFilesProjectVisitor :
|
||||
List String
|
||||
List FilePattern
|
||||
-> (List { fileKey : ExtraFileKey, path : String, content : String } -> projectContext -> ( List (Error { useErrorForModule : () }), projectContext ))
|
||||
-> ProjectRuleSchema schemaState projectContext moduleContext
|
||||
-> ProjectRuleSchema { schemaState | hasAtLeastOneVisitor : () } projectContext moduleContext
|
||||
withExtraFilesProjectVisitor requestedFiles baseVisitor (ProjectRuleSchema schema) =
|
||||
case parseGlobs requestedFiles of
|
||||
Ok stringableGlobs ->
|
||||
withExtraFilesProjectVisitor filePatterns baseVisitor (ProjectRuleSchema schema) =
|
||||
case FilePattern.compact filePatterns of
|
||||
Ok filePatternSummary ->
|
||||
let
|
||||
globs : List Glob
|
||||
globs =
|
||||
List.map .glob stringableGlobs
|
||||
|
||||
visitor : List { fileKey : ExtraFileKey, path : String, content : String } -> projectContext -> ( List (Error {}), projectContext )
|
||||
visitor files context =
|
||||
baseVisitor (List.filter (globMatch globs) files) context
|
||||
baseVisitor (List.filter (\file -> FilePattern.match filePatternSummary file.path) files) context
|
||||
|> Tuple.mapFirst removeErrorPhantomTypes
|
||||
in
|
||||
ProjectRuleSchema
|
||||
@ -1930,9 +1927,9 @@ withExtraFilesProjectVisitor requestedFiles baseVisitor (ProjectRuleSchema schem
|
||||
, extraFileRequest =
|
||||
case schema.extraFileRequest of
|
||||
Ok previous ->
|
||||
Ok (previous ++ stringableGlobs)
|
||||
Ok (FilePattern.toStrings filePatternSummary :: previous)
|
||||
|
||||
Err previous ->
|
||||
Err _ ->
|
||||
schema.extraFileRequest
|
||||
}
|
||||
|
||||
@ -2465,21 +2462,17 @@ withElmJsonModuleVisitor visitor (ModuleRuleSchema schema) =
|
||||
{-| REPLACEME
|
||||
-}
|
||||
withExtraFilesModuleVisitor :
|
||||
List String
|
||||
List FilePattern
|
||||
-> (List { path : String, content : String } -> moduleContext -> moduleContext)
|
||||
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
|
||||
-> ModuleRuleSchema { schemaState | canCollectProjectData : () } moduleContext
|
||||
withExtraFilesModuleVisitor requestedFiles baseVisitor (ModuleRuleSchema schema) =
|
||||
case parseGlobs requestedFiles of
|
||||
Ok stringableGlobs ->
|
||||
withExtraFilesModuleVisitor filePatterns baseVisitor (ModuleRuleSchema schema) =
|
||||
case FilePattern.compact filePatterns of
|
||||
Ok filePatternSummary ->
|
||||
let
|
||||
globs : List Glob
|
||||
globs =
|
||||
List.map .glob stringableGlobs
|
||||
|
||||
visitor : List { path : String, content : String } -> moduleContext -> moduleContext
|
||||
visitor files context =
|
||||
baseVisitor (List.filter (globMatch globs) files) context
|
||||
baseVisitor (List.filter (\file -> FilePattern.match filePatternSummary file.path) files) context
|
||||
in
|
||||
ModuleRuleSchema
|
||||
{ schema
|
||||
@ -2487,9 +2480,9 @@ withExtraFilesModuleVisitor requestedFiles baseVisitor (ModuleRuleSchema schema)
|
||||
, extraFileRequest =
|
||||
case schema.extraFileRequest of
|
||||
Ok previous ->
|
||||
Ok (previous ++ stringableGlobs)
|
||||
Ok (FilePattern.toStrings filePatternSummary :: previous)
|
||||
|
||||
Err previous ->
|
||||
Err _ ->
|
||||
schema.extraFileRequest
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ elm-review --template jfmengels/elm-review/example --rules Docs.NoMissingChangel
|
||||
import Elm.Project exposing (Project)
|
||||
import Elm.Syntax.Range exposing (Range)
|
||||
import Elm.Version
|
||||
import Review.FilePattern as FilePattern
|
||||
import Review.Fix as Fix
|
||||
import Review.Rule as Rule exposing (Rule)
|
||||
|
||||
@ -55,7 +56,7 @@ rule : Configuration -> Rule
|
||||
rule (Configuration { changelogPath }) =
|
||||
Rule.newProjectRuleSchema "Docs.NoMissingChangelogEntry" initialProjectContext
|
||||
|> Rule.withElmJsonProjectVisitor elmJsonVisitor
|
||||
|> Rule.withExtraFilesProjectVisitor [ Maybe.withDefault defaultPath changelogPath ] (extraFilesVisitor changelogPath)
|
||||
|> Rule.withExtraFilesProjectVisitor [ FilePattern.include (Maybe.withDefault defaultPath changelogPath) ] (extraFilesVisitor changelogPath)
|
||||
|> Rule.providesFixesForProjectRule
|
||||
|> Rule.fromProjectRuleSchema
|
||||
|
||||
|
@ -5,6 +5,7 @@ import Elm.Syntax.Expression as Expression exposing (Expression)
|
||||
import Elm.Syntax.Import exposing (Import)
|
||||
import Elm.Syntax.Node as Node exposing (Node(..))
|
||||
import Elm.Syntax.Pattern exposing (Pattern)
|
||||
import Review.FilePattern as FilePattern
|
||||
import Review.Project as Project exposing (Project)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
import Review.Test
|
||||
@ -32,8 +33,8 @@ all =
|
||||
|> Rule.withElmJsonModuleVisitor (\_ context -> context ++ "\n1.2 - withElmJsonModuleVisitor")
|
||||
|> Rule.withReadmeModuleVisitor (\_ context -> context ++ "\n2.1 - withReadmeModuleVisitor")
|
||||
|> Rule.withReadmeModuleVisitor (\_ context -> context ++ "\n2.2 - withReadmeModuleVisitor")
|
||||
|> Rule.withExtraFilesModuleVisitor [ "first.txt" ] (\files context -> context ++ "\n3.1 - withExtraFilesModuleVisitor " ++ (List.map .path files |> String.join ", "))
|
||||
|> Rule.withExtraFilesModuleVisitor [ "last.txt" ] (\files context -> context ++ "\n3.2 - withExtraFilesModuleVisitor " ++ (List.map .path files |> String.join ", "))
|
||||
|> Rule.withExtraFilesModuleVisitor [ FilePattern.include "first.txt" ] (\files context -> context ++ "\n3.1 - withExtraFilesModuleVisitor " ++ (List.map .path files |> String.join ", "))
|
||||
|> Rule.withExtraFilesModuleVisitor [ FilePattern.include "last.txt" ] (\files context -> context ++ "\n3.2 - withExtraFilesModuleVisitor " ++ (List.map .path files |> String.join ", "))
|
||||
|> Rule.withDirectDependenciesModuleVisitor (\_ context -> context ++ "\n4.1 - withDirectDependenciesModuleVisitor")
|
||||
|> Rule.withDirectDependenciesModuleVisitor (\_ context -> context ++ "\n4.2 - withDirectDependenciesModuleVisitor")
|
||||
|> Rule.withDependenciesModuleVisitor (\_ context -> context ++ "\n4.3 - withDependenciesModuleVisitor")
|
||||
|
@ -1,5 +1,6 @@
|
||||
module Review.Rule.WithExtraFilesVisitorTest exposing (all)
|
||||
|
||||
import Review.FilePattern as FilePattern exposing (FilePattern)
|
||||
import Review.Project as Project exposing (Project)
|
||||
import Review.Rule as Rule exposing (Error, Rule)
|
||||
import Review.Test
|
||||
@ -20,7 +21,7 @@ all =
|
||||
|
||||
rule : Rule
|
||||
rule =
|
||||
createRule (Rule.withExtraFilesModuleVisitor [ "foo/some-file.css" ] extraFilesModuleVisitor)
|
||||
createRule (Rule.withExtraFilesModuleVisitor [ FilePattern.include "foo/some-file.css" ] extraFilesModuleVisitor)
|
||||
in
|
||||
"""module A exposing (a)
|
||||
a = 1
|
||||
@ -44,7 +45,7 @@ a = 1
|
||||
|
||||
rule : Rule
|
||||
rule =
|
||||
createRule (Rule.withExtraFilesModuleVisitor [ "foo/some-file.css" ] extraFilesModuleVisitor)
|
||||
createRule (Rule.withExtraFilesModuleVisitor [ FilePattern.include "foo/some-file.css" ] extraFilesModuleVisitor)
|
||||
in
|
||||
"""module A exposing (a)
|
||||
a = 1
|
||||
@ -69,8 +70,8 @@ a = 1
|
||||
rule : Rule
|
||||
rule =
|
||||
createRule
|
||||
(Rule.withExtraFilesModuleVisitor [ "a.txt", "c.txt" ] (reportsFileNames "A")
|
||||
>> Rule.withExtraFilesModuleVisitor [ "b.txt" ] (reportsFileNames "B")
|
||||
(Rule.withExtraFilesModuleVisitor [ FilePattern.include "a.txt", FilePattern.include "c.txt" ] (reportsFileNames "A")
|
||||
>> Rule.withExtraFilesModuleVisitor [ FilePattern.include "b.txt" ] (reportsFileNames "B")
|
||||
)
|
||||
in
|
||||
"""module A exposing (a)
|
||||
@ -90,7 +91,7 @@ a = 1
|
||||
\() ->
|
||||
createRule
|
||||
(Rule.withExtraFilesModuleVisitor
|
||||
[ "** " ]
|
||||
[ FilePattern.include "** " ]
|
||||
(reportsFileNames "A")
|
||||
)
|
||||
|> Review.Test.expectConfigurationError
|
||||
|
Loading…
Reference in New Issue
Block a user