@@ -518,7 +518,7 @@ public bool IsDscResourceClassBased(ScriptBlockAst ast)
518
518
return false ;
519
519
}
520
520
521
- #if ! ( PSV3 || PSV4 )
521
+ #if ! ( PSV3 || PSV4 )
522
522
523
523
List < string > dscResourceFunctionNames = new List < string > ( new string [ ] { "Test" , "Get" , "Set" } ) ;
524
524
@@ -534,7 +534,7 @@ item is TypeDefinitionAst
534
534
return true ;
535
535
}
536
536
537
- #endif
537
+ #endif
538
538
539
539
return false ;
540
540
}
@@ -1074,7 +1074,7 @@ public string GetTypeFromMemberExpressionAst(MemberExpressionAst memberAst, Ast
1074
1074
1075
1075
#else
1076
1076
1077
- return GetTypeFromMemberExpressionAstHelper ( memberAst , psClass , details ) ;
1077
+ return GetTypeFromMemberExpressionAstHelper ( memberAst , psClass , details ) ;
1078
1078
1079
1079
#endif
1080
1080
}
@@ -1349,49 +1349,48 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1349
1349
1350
1350
List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
1351
1351
var offsetArr = GetOffsetArray ( diagnostics ) ;
1352
- int recordIndex = 0 ;
1353
- int startRecord = 0 ;
1354
- bool [ ] suppressed = new bool [ diagnostics . Count ] ;
1355
- foreach ( RuleSuppression ruleSuppression in ruleSuppressions )
1356
- {
1357
- int suppressionCount = 0 ;
1358
- while ( startRecord < diagnostics . Count
1359
- // && diagnostics[startRecord].Extent.StartOffset < ruleSuppression.StartOffset)
1360
- // && diagnostics[startRecord].Extent.StartLineNumber < ruleSuppression.st)
1361
- && offsetArr [ startRecord ] != null && offsetArr [ startRecord ] . Item1 < ruleSuppression . StartOffset )
1362
- {
1363
- startRecord += 1 ;
1364
- }
1365
-
1366
- // at this point, start offset of startRecord is greater or equals to rulesuppression.startoffset
1367
- recordIndex = startRecord ;
1352
+ bool [ ] applied = new bool [ ruleSuppressions . Count ] ;
1368
1353
1369
- while ( recordIndex < diagnostics . Count )
1354
+ for ( int i = 0 ; i < diagnostics . Count ; i ++ )
1355
+ {
1356
+ DiagnosticRecord record = diagnostics [ i ] ;
1357
+ var curOffset = offsetArr [ i ] ;
1358
+ List < RuleSuppression > suppressions = new List < RuleSuppression > ( ) ;
1359
+ for ( int ruleSuppressionIndex = 0 ; ruleSuppressionIndex < ruleSuppressions . Count ; ruleSuppressionIndex ++ )
1370
1360
{
1371
- DiagnosticRecord record = diagnostics [ recordIndex ] ;
1372
- var curOffset = offsetArr [ recordIndex ] ;
1373
-
1374
- //if (record.Extent.EndOffset > ruleSuppression.EndOffset)
1375
- if ( curOffset != null && curOffset . Item2 > ruleSuppression . EndOffset )
1361
+ RuleSuppression ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
1362
+ //if (record.Extent.StartOffset < ruleSuppression.StartOffset||record.Extent.EndOffset > ruleSuppression.EndOffset)
1363
+ if ( curOffset != null && ( curOffset . Item1 < ruleSuppression . StartOffset || curOffset . Item2 > ruleSuppression . EndOffset ) )
1376
1364
{
1377
- break ;
1365
+ continue ;
1378
1366
}
1379
1367
1380
1368
// we suppress if there is no suppression id or if there is suppression id and it matches
1381
1369
if ( string . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID )
1382
1370
|| ( ! String . IsNullOrWhiteSpace ( record . RuleSuppressionID ) &&
1383
1371
string . Equals ( ruleSuppression . RuleSuppressionID , record . RuleSuppressionID , StringComparison . OrdinalIgnoreCase ) ) )
1384
1372
{
1385
- suppressed [ recordIndex ] = true ;
1386
- suppressedRecords . Add ( new SuppressedRecord ( record , ruleSuppression ) ) ;
1387
- suppressionCount += 1 ;
1373
+ ruleSuppression . Kind = "InSource" ;
1374
+ suppressions . Add ( ruleSuppression ) ;
1375
+ applied [ ruleSuppressionIndex ] = true ;
1388
1376
}
1377
+ }
1389
1378
1390
- recordIndex += 1 ;
1379
+ if ( suppressions . Count ( ) != 0 )
1380
+ {
1381
+ suppressedRecords . Add ( new SuppressedRecord ( record , suppressions ) ) ;
1391
1382
}
1383
+ else
1384
+ {
1385
+ unSuppressedRecords . Add ( diagnostics [ i ] ) ;
1386
+ }
1387
+ }
1392
1388
1393
- // If we cannot found any error but the rulesuppression has a rulesuppressionid then it must be used wrongly
1394
- if ( ! String . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && suppressionCount == 0 )
1389
+ // If we cannot found any error but the rulesuppression has a rulesuppressionid then it must be used wrongly
1390
+ for ( int ruleSuppressionIndex = 0 ; ruleSuppressionIndex < ruleSuppressions . Count ; ruleSuppressionIndex ++ )
1391
+ {
1392
+ RuleSuppression ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
1393
+ if ( ( ! String . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) ) && ! applied [ ruleSuppressionIndex ] )
1395
1394
{
1396
1395
// checks whether are given a string or a file path
1397
1396
if ( String . IsNullOrWhiteSpace ( diagnostics . First ( ) . Extent . File ) )
@@ -1409,14 +1408,6 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1409
1408
}
1410
1409
}
1411
1410
1412
- for ( int i = 0 ; i < suppressed . Length ; i += 1 )
1413
- {
1414
- if ( ! suppressed [ i ] )
1415
- {
1416
- unSuppressedRecords . Add ( diagnostics [ i ] ) ;
1417
- }
1418
- }
1419
-
1420
1411
return result ;
1421
1412
}
1422
1413
@@ -2036,7 +2027,7 @@ private static InvalidDataException CreateInvalidDataException(IScriptExtent ext
2036
2027
}
2037
2028
2038
2029
2039
- #endregion Methods
2030
+ #endregion Methods
2040
2031
}
2041
2032
2042
2033
0 commit comments