diff --git a/src/FSharpLint.Core/Framework/Rules.fs b/src/FSharpLint.Core/Framework/Rules.fs index d53629800..74dfb5f70 100644 --- a/src/FSharpLint.Core/Framework/Rules.fs +++ b/src/FSharpLint.Core/Framework/Rules.fs @@ -97,12 +97,12 @@ let toWarning (identifier:string) (ruleName:string) (filePath:string) (lines:str let runAstNodeRule (rule:RuleMetadata) (config:AstNodeRuleParams) = rule.RuleConfig.Runner config - |> Array.map (toWarning rule.Identifier rule.Name config.FilePath config.Lines) + |> Array.mapIfNotEmpty (toWarning rule.Identifier rule.Name config.FilePath config.Lines) let runLineRuleWithContext (rule:RuleMetadata>) (context:'Context) (config:LineRuleParams) = rule.RuleConfig.Runner context config - |> Array.map (toWarning rule.Identifier rule.Name config.FilePath config.Lines) + |> Array.mapIfNotEmpty (toWarning rule.Identifier rule.Name config.FilePath config.Lines) let runLineRule (rule:RuleMetadata) (config:LineRuleParams) = rule.RuleConfig.Runner config - |> Array.map (toWarning rule.Identifier rule.Name config.FilePath config.Lines) + |> Array.mapIfNotEmpty (toWarning rule.Identifier rule.Name config.FilePath config.Lines) diff --git a/src/FSharpLint.Core/Framework/Utilities.fs b/src/FSharpLint.Core/Framework/Utilities.fs index 8973b8ac1..f51f0b3c0 100644 --- a/src/FSharpLint.Core/Framework/Utilities.fs +++ b/src/FSharpLint.Core/Framework/Utilities.fs @@ -23,6 +23,14 @@ module Dictionary = dict.Add(key, value) +module Array = + + let inline mapIfNotEmpty ([] mapping: 'Source -> 'Dest) (array: 'Source array) = + if Array.isEmpty array + then Array.empty + else + Array.map mapping array + module ExpressionUtilities = open System