Skip to content

Commit 791e2c7

Browse files
author
Kapil Borle
committed
Remove SuppressRule method redundancy
1 parent e847cf9 commit 791e2c7

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,22 +1454,27 @@ private Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
14541454
}
14551455
return records;
14561456
}
1457+
1458+
/// <summary>
1459+
/// Wrapper around SuppressRule method.
1460+
///
1461+
/// This enables suppressing external rules (written in PowerShell).
1462+
/// Since there can be an inconsistency between the rule name in
1463+
/// diagnostic record and the actual rule (function) name, we use
1464+
/// the diagnostic record rule name for suppression
1465+
/// </summary>
1466+
/// <param name="ruleSuppressions"></param>
1467+
/// <param name="ruleDiagnosticRecord"></param>
1468+
/// <returns>Returns a tuple of suppressed and diagnostic records</returns>
14571469
private Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1458-
DiagnosticRecord ruleDiagnosticRecord,
1459-
Dictionary<string, List<RuleSuppression>> ruleSuppressions
1470+
Dictionary<string, List<RuleSuppression>> ruleSuppressions,
1471+
DiagnosticRecord ruleDiagnosticRecord
14601472
)
14611473
{
1462-
List<ErrorRecord> suppressRuleErrors;
1463-
var records = Helper.Instance.SuppressRule(
1474+
return SuppressRule(
14641475
ruleDiagnosticRecord.RuleName,
14651476
ruleSuppressions,
1466-
new List<DiagnosticRecord> { ruleDiagnosticRecord },
1467-
out suppressRuleErrors);
1468-
foreach (var error in suppressRuleErrors)
1469-
{
1470-
this.outputWriter.WriteError(error);
1471-
}
1472-
return records;
1477+
new List<DiagnosticRecord> { ruleDiagnosticRecord });
14731478
}
14741479

14751480
/// <summary>
@@ -1771,7 +1776,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
17711776

17721777
foreach (var ruleRecord in this.GetExternalRecord(scriptAst, scriptTokens, exRules.ToArray(), fileName))
17731778
{
1774-
var records = SuppressRule(ruleRecord, ruleSuppressions);
1779+
var records = SuppressRule(ruleSuppressions, ruleRecord);
17751780
foreach (var record in records.Item2)
17761781
{
17771782
diagnostics.Add(record);

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ Write-Host "write-host"
137137
$ruleViolations.Count | Should Be 1
138138
}
139139
}
140-
141-
142140
}
143141
}
144142

0 commit comments

Comments
 (0)