Skip to content

Commit 228b727

Browse files
author
Quoc Truong
committed
Apply rule suppression for DSC and Token rules
1 parent 3567d12 commit 228b727

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

Engine/Commands/InvokeScriptAnalyzerCommand.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ private void AnalyzeFile(string filePath)
356356
// We want the Engine to continue functioning even if one or more Rules throws an exception
357357
try
358358
{
359-
diagnostics.AddRange(tokenRule.AnalyzeTokens(tokens, fileName));
359+
diagnostics.AddRange(Helper.Instance.SuppressRule(tokenRule.GetName(), ruleSuppressions, tokenRule.AnalyzeTokens(tokens, fileName).ToList()));
360360
}
361361
catch (Exception tokenRuleException)
362362
{
@@ -384,7 +384,7 @@ private void AnalyzeFile(string filePath)
384384
// We want the Engine to continue functioning even if one or more Rules throws an exception
385385
try
386386
{
387-
diagnostics.AddRange(dscResourceRule.AnalyzeDSCClass(ast, filePath));
387+
diagnostics.AddRange(Helper.Instance.SuppressRule(dscResourceRule.GetName(), ruleSuppressions, dscResourceRule.AnalyzeDSCClass(ast, filePath).ToList()));
388388
}
389389
catch (Exception dscResourceRuleException)
390390
{
@@ -426,7 +426,7 @@ private void AnalyzeFile(string filePath)
426426
// We want the Engine to continue functioning even if one or more Rules throws an exception
427427
try
428428
{
429-
diagnostics.AddRange(dscResourceRule.AnalyzeDSCResource(ast, filePath));
429+
diagnostics.AddRange(Helper.Instance.SuppressRule(dscResourceRule.GetName(), ruleSuppressions, dscResourceRule.AnalyzeDSCResource(ast, filePath).ToList()));
430430
}
431431
catch (Exception dscResourceRuleException)
432432
{

Engine/Generic/RuleSuppression.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public string RuleName
6262
&& (ScriptAnalyzer.Instance.TokenRules != null
6363
&& ScriptAnalyzer.Instance.TokenRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0)
6464
&& (ScriptAnalyzer.Instance.ExternalRules != null
65-
&& ScriptAnalyzer.Instance.ExternalRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0))
65+
&& ScriptAnalyzer.Instance.ExternalRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0)
66+
&& (ScriptAnalyzer.Instance.DSCResourceRules != null
67+
&& ScriptAnalyzer.Instance.DSCResourceRules.Count(item => String.Equals(item.GetName(), _ruleName, StringComparison.OrdinalIgnoreCase)) == 0))
6668
{
6769
Error = String.Format(Strings.RuleSuppressionRuleNameNotFound, _ruleName);
6870
}

0 commit comments

Comments
 (0)