Skip to content

Commit bbfd1d9

Browse files
charlieschmidtKapil Borle
authored andcommitted
Suppress External Rules (#585)
* External/Custom rule supression * Revert to the previous GetExternalRecord() call on all external rules, rather than 1-by-1 to continue to take advantage of the runspacepool stuff. New SupressRule() function that takes a single DiagnosticRecord and list of suppressions - bounces the RuleName of the record against that list.
1 parent edba7cc commit bbfd1d9

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

Engine/ScriptAnalyzer.cs

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,23 @@ private Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
14541454
}
14551455
return records;
14561456
}
1457+
private Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1458+
DiagnosticRecord ruleDiagnosticRecord,
1459+
Dictionary<string, List<RuleSuppression>> ruleSuppressions
1460+
)
1461+
{
1462+
List<ErrorRecord> suppressRuleErrors;
1463+
var records = Helper.Instance.SuppressRule(
1464+
ruleDiagnosticRecord.RuleName,
1465+
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;
1473+
}
14571474

14581475
/// <summary>
14591476
/// Analyzes the syntax tree of a script file that has already been parsed.
@@ -1752,13 +1769,21 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
17521769
}
17531770
}
17541771

1755-
foreach (var record in this.GetExternalRecord(scriptAst, scriptTokens, exRules.ToArray(), fileName))
1772+
foreach (var ruleRecord in this.GetExternalRecord(scriptAst, scriptTokens, exRules.ToArray(), fileName))
17561773
{
1757-
diagnostics.Add(record);
1774+
var records = SuppressRule(ruleRecord, ruleSuppressions);
1775+
foreach (var record in records.Item2)
1776+
{
1777+
diagnostics.Add(record);
1778+
}
1779+
foreach (var suppressedRec in records.Item1)
1780+
{
1781+
suppressed.Add(suppressedRec);
1782+
}
17581783
}
17591784
}
1760-
1761-
#endregion
1785+
1786+
#endregion
17621787

17631788
// Need to reverse the concurrentbag to ensure that results are sorted in the increasing order of line numbers
17641789
IEnumerable<DiagnosticRecord> diagnosticsList = diagnostics.Reverse();

0 commit comments

Comments
 (0)