@@ -1385,6 +1385,31 @@ bool IsRuleAllowed(IRule rule)
1385
1385
&& IsSeverityAllowed ( allowedSeverities , rule ) ;
1386
1386
}
1387
1387
1388
+ /// <summary>
1389
+ /// Wrapper around the Helper.SuppressRule method
1390
+ /// </summary>
1391
+ /// <param name="ruleName"></param>
1392
+ /// <param name="ruleSuppressions"></param>
1393
+ /// <param name="ruleDiagnosticRecords"></param>
1394
+ /// <returns>Returns a tuple of suppressed and diagnostic records</returns>
1395
+ private Tuple < List < SuppressedRecord > , List < DiagnosticRecord > > SuppressRule (
1396
+ string ruleName ,
1397
+ Dictionary < string , List < RuleSuppression > > ruleSuppressions ,
1398
+ List < DiagnosticRecord > ruleDiagnosticRecords )
1399
+ {
1400
+ List < ErrorRecord > suppressRuleErrors ;
1401
+ var records = Helper . Instance . SuppressRule (
1402
+ ruleName ,
1403
+ ruleSuppressions ,
1404
+ ruleDiagnosticRecords ,
1405
+ out suppressRuleErrors ) ;
1406
+ foreach ( var error in suppressRuleErrors )
1407
+ {
1408
+ this . outputWriter . WriteError ( error ) ;
1409
+ }
1410
+ return records ;
1411
+ }
1412
+
1388
1413
/// <summary>
1389
1414
/// Analyzes the syntax tree of a script file that has already been parsed.
1390
1415
/// </summary>
@@ -1445,7 +1470,6 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1445
1470
if ( this . ScriptRules != null )
1446
1471
{
1447
1472
var allowedRules = this . ScriptRules . Where ( IsRuleAllowed ) ;
1448
-
1449
1473
if ( allowedRules . Any ( ) )
1450
1474
{
1451
1475
var tasks = allowedRules . Select ( scriptRule => Task . Factory . StartNew ( ( ) =>
@@ -1468,7 +1492,14 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1468
1492
}
1469
1493
else if ( ! helpRule && ! helpFile )
1470
1494
{
1471
- var records = Helper . Instance . SuppressRule ( scriptRule . GetName ( ) , ruleSuppressions , scriptRule . AnalyzeScript ( scriptAst , scriptAst . Extent . File ) . ToList ( ) ) ;
1495
+ List < ErrorRecord > suppressRuleErrors ;
1496
+ var ruleRecords = scriptRule . AnalyzeScript ( scriptAst , scriptAst . Extent . File ) . ToList ( ) ;
1497
+ var records = Helper . Instance . SuppressRule (
1498
+ scriptRule . GetName ( ) ,
1499
+ ruleSuppressions ,
1500
+ ruleRecords ,
1501
+ out suppressRuleErrors ) ;
1502
+ result . AddRange ( suppressRuleErrors ) ;
1472
1503
foreach ( var record in records . Item2 )
1473
1504
{
1474
1505
diagnostics . Add ( record ) ;
@@ -1486,9 +1517,7 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1486
1517
1487
1518
verboseOrErrors . Add ( result ) ;
1488
1519
} ) ) ;
1489
-
1490
1520
Task . Factory . ContinueWhenAll ( tasks . ToArray ( ) , t => verboseOrErrors . CompleteAdding ( ) ) ;
1491
-
1492
1521
while ( ! verboseOrErrors . IsCompleted )
1493
1522
{
1494
1523
List < object > data = null ;
@@ -1501,9 +1530,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1501
1530
if ( data != null )
1502
1531
{
1503
1532
this . outputWriter . WriteVerbose ( data [ 0 ] as string ) ;
1504
- if ( data . Count == 2 )
1533
+ if ( data . Count > 1 )
1505
1534
{
1506
- this . outputWriter . WriteError ( data [ 1 ] as ErrorRecord ) ;
1535
+ for ( int count = 1 ; count < data . Count ; count ++ )
1536
+ {
1537
+ this . outputWriter . WriteError ( data [ count ] as ErrorRecord ) ;
1538
+ }
1507
1539
}
1508
1540
}
1509
1541
}
@@ -1526,7 +1558,8 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1526
1558
// We want the Engine to continue functioning even if one or more Rules throws an exception
1527
1559
try
1528
1560
{
1529
- var records = Helper . Instance . SuppressRule ( tokenRule . GetName ( ) , ruleSuppressions , tokenRule . AnalyzeTokens ( scriptTokens , filePath ) . ToList ( ) ) ;
1561
+ var ruleRecords = tokenRule . AnalyzeTokens ( scriptTokens , filePath ) . ToList ( ) ;
1562
+ var records = SuppressRule ( tokenRule . GetName ( ) , ruleSuppressions , ruleRecords ) ;
1530
1563
foreach ( var record in records . Item2 )
1531
1564
{
1532
1565
diagnostics . Add ( record ) ;
@@ -1584,16 +1617,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1584
1617
// We want the Engine to continue functioning even if one or more Rules throws an exception
1585
1618
try
1586
1619
{
1587
- #if PSV3
1588
-
1620
+ #if PSV3
1589
1621
var records = Helper . Instance . SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , null ) ;
1590
-
1591
- #else
1592
-
1593
- var records = Helper . Instance . SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , dscResourceRule . AnalyzeDSCClass ( scriptAst , filePath ) . ToList ( ) ) ;
1594
-
1595
- #endif
1596
-
1622
+ #else
1623
+ var ruleRecords = dscResourceRule . AnalyzeDSCClass ( scriptAst , filePath ) . ToList ( ) ;
1624
+ var records = SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , ruleRecords ) ;
1625
+ #endif
1597
1626
foreach ( var record in records . Item2 )
1598
1627
{
1599
1628
diagnostics . Add ( record ) ;
@@ -1625,7 +1654,8 @@ public IEnumerable<DiagnosticRecord> AnalyzeSyntaxTree(
1625
1654
// We want the Engine to continue functioning even if one or more Rules throws an exception
1626
1655
try
1627
1656
{
1628
- var records = Helper . Instance . SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , dscResourceRule . AnalyzeDSCResource ( scriptAst , filePath ) . ToList ( ) ) ;
1657
+ var ruleRecords = dscResourceRule . AnalyzeDSCResource ( scriptAst , filePath ) . ToList ( ) ;
1658
+ var records = SuppressRule ( dscResourceRule . GetName ( ) , ruleSuppressions , ruleRecords ) ;
1629
1659
foreach ( var record in records . Item2 )
1630
1660
{
1631
1661
diagnostics . Add ( record ) ;
0 commit comments