diff --git a/src/FSharp.Analyzers.Cli/Program.fs b/src/FSharp.Analyzers.Cli/Program.fs index 990a3bb..65fa85b 100644 --- a/src/FSharp.Analyzers.Cli/Program.fs +++ b/src/FSharp.Analyzers.Cli/Program.fs @@ -565,14 +565,19 @@ let main argv = let includeAnalyzers = results.GetResult(<@ Include_Analyzers @>, []) match excludeAnalyzers, includeAnalyzers with - | e, [] -> Exclude(Set.ofList e) - | [], i -> Include(Set.ofList i) + | e, [] -> + fun (s: string) -> e |> List.map Glob |> List.exists (fun g -> g.IsMatch s) + |> ExcludeFilter + | [], i -> + fun (s: string) -> i |> List.map Glob |> List.exists (fun g -> g.IsMatch s) + |> IncludeFilter | _e, i -> logger.LogWarning( "--exclude-analyzers and --include-analyzers are mutually exclusive, ignoring --exclude-analyzers" ) - Include(Set.ofList i) + fun (s: string) -> i |> List.map Glob |> List.exists (fun g -> g.IsMatch s) + |> IncludeFilter AssemblyLoadContext.Default.add_Resolving (fun _ctx assemblyName -> if assemblyName.Name <> "FSharp.Core" then diff --git a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fs b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fs index 6fe75eb..6ac5a39 100644 --- a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fs +++ b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fs @@ -6,7 +6,6 @@ open System.Collections.Concurrent open System.Reflection open System.Runtime.Loader open System.Text.RegularExpressions -open GlobExpressions open McMaster.NETCore.Plugins open Microsoft.Extensions.Logging @@ -129,8 +128,8 @@ module Client = |> Seq.toList type ExcludeInclude = - | Exclude of string Set - | Include of string Set + | ExcludeFilter of (string -> bool) + | IncludeFilter of (string -> bool) type Client<'TAttribute, 'TContext when 'TAttribute :> AnalyzerAttribute and 'TContext :> Context>(logger: ILogger) = do TASTCollecting.logger <- logger @@ -142,13 +141,6 @@ type Client<'TAttribute, 'TContext when 'TAttribute :> AnalyzerAttribute and 'TC member x.LoadAnalyzers(dir: string, ?excludeInclude: ExcludeInclude) : int * int = if Directory.Exists dir then - - let excludeInclude = - match excludeInclude with - | Some(Exclude excluded) -> Some(Choice1Of2(List.ofSeq excluded |> List.map Glob)) - | Some(Include included) -> Some(Choice2Of2(List.ofSeq included |> List.map Glob)) - | None -> None - let analyzerAssemblies = let regex = Regex(@".*test.*\.dll$") @@ -208,9 +200,8 @@ type Client<'TAttribute, 'TContext when 'TAttribute :> AnalyzerAttribute and 'TC |> Seq.collect (Client.analyzersFromType<'TAttribute, 'TContext> path) |> Seq.filter (fun registeredAnalyzer -> match excludeInclude with - | Some(Choice1Of2 excluded) -> - let shouldExclude = - excluded |> List.exists (fun g -> g.IsMatch registeredAnalyzer.Name) + | Some(ExcludeFilter excludeFilter) -> + let shouldExclude = excludeFilter registeredAnalyzer.Name if shouldExclude then logger.LogInformation( @@ -220,9 +211,8 @@ type Client<'TAttribute, 'TContext when 'TAttribute :> AnalyzerAttribute and 'TC ) not shouldExclude - | Some(Choice2Of2 included) -> - let shouldInclude = - included |> List.exists (fun g -> g.IsMatch registeredAnalyzer.Name) + | Some(IncludeFilter includeFilter) -> + let shouldInclude = includeFilter registeredAnalyzer.Name if shouldInclude then logger.LogInformation( diff --git a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fsi b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fsi index b5e5ad7..2e24b25 100644 --- a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fsi +++ b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.Client.fsi @@ -9,10 +9,10 @@ type AnalysisResult = } type ExcludeInclude = - /// Analyzers in this set should be ignored. - | Exclude of string Set - /// Analyzers in this set should be used exclusively, while all others are ignored. - | Include of string Set + /// A predicate function to exclude Analyzers. + | ExcludeFilter of (string -> bool) + /// A predicate function to include Analyzers exclusively, while all others are ignored. + | IncludeFilter of (string -> bool) type Client<'TAttribute, 'TContext when 'TAttribute :> AnalyzerAttribute and 'TContext :> Context> = new: logger: ILogger -> Client<'TAttribute, 'TContext> diff --git a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsproj b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsproj index 433cc32..0c2f432 100644 --- a/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsproj +++ b/src/FSharp.Analyzers.SDK/FSharp.Analyzers.SDK.fsproj @@ -24,6 +24,5 @@ - \ No newline at end of file