@@ -1310,15 +1310,17 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1310
1310
}
1311
1311
1312
1312
List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
1313
-
1313
+ var offsetArr = GetOffsetArray ( diagnostics ) ;
1314
1314
int recordIndex = 0 ;
1315
1315
int startRecord = 0 ;
1316
1316
bool [ ] suppressed = new bool [ diagnostics . Count ] ;
1317
-
1318
1317
foreach ( RuleSuppression ruleSuppression in ruleSuppressions )
1319
1318
{
1320
1319
int suppressionCount = 0 ;
1321
- while ( startRecord < diagnostics . Count && diagnostics [ startRecord ] . Extent . StartOffset < ruleSuppression . StartOffset )
1320
+ while ( startRecord < diagnostics . Count
1321
+ // && diagnostics[startRecord].Extent.StartOffset < ruleSuppression.StartOffset)
1322
+ // && diagnostics[startRecord].Extent.StartLineNumber < ruleSuppression.st)
1323
+ && offsetArr [ startRecord ] . Item1 < ruleSuppression . StartOffset )
1322
1324
{
1323
1325
startRecord += 1 ;
1324
1326
}
@@ -1329,8 +1331,10 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1329
1331
while ( recordIndex < diagnostics . Count )
1330
1332
{
1331
1333
DiagnosticRecord record = diagnostics [ recordIndex ] ;
1334
+ var curOffset = offsetArr [ recordIndex ] ;
1332
1335
1333
- if ( record . Extent . EndOffset > ruleSuppression . EndOffset )
1336
+ //if (record.Extent.EndOffset > ruleSuppression.EndOffset)
1337
+ if ( curOffset . Item2 > ruleSuppression . EndOffset )
1334
1338
{
1335
1339
break ;
1336
1340
}
@@ -1378,6 +1382,57 @@ public Tuple<List<SuppressedRecord>, List<DiagnosticRecord>> SuppressRule(
1378
1382
return result ;
1379
1383
}
1380
1384
1385
+ private Tuple < int , int > [ ] GetOffsetArray ( List < DiagnosticRecord > diagnostics )
1386
+ {
1387
+ Func < int , int , Tuple < int , int > > GetTuple = ( x , y ) => new Tuple < int , int > ( x , y ) ;
1388
+ Func < Tuple < int , int > > GetDefaultTuple = ( ) => GetTuple ( 0 , 0 ) ;
1389
+ var offsets = new Tuple < int , int > [ diagnostics . Count ] ;
1390
+ for ( int k = 0 ; k < diagnostics . Count ; k ++ )
1391
+ {
1392
+ var ext = diagnostics [ k ] . Extent ;
1393
+ if ( ext . StartOffset == 0 && ext . EndOffset == 0 )
1394
+ {
1395
+ // check if line and column number correspond to 0 offsets
1396
+ if ( ext . StartLineNumber == 1
1397
+ && ext . StartColumnNumber == 1
1398
+ && ext . EndLineNumber == 1
1399
+ && ext . EndColumnNumber == 1 )
1400
+ {
1401
+ offsets [ k ] = GetDefaultTuple ( ) ;
1402
+ continue ;
1403
+ }
1404
+ // created using the ScriptExtent constructor, which sets
1405
+ // StartOffset and EndOffset to 0
1406
+ // find the token the corresponding start line and column number
1407
+ var startToken = Tokens . Where ( x
1408
+ => x . Extent . StartLineNumber == ext . StartLineNumber
1409
+ && x . Extent . StartColumnNumber == ext . StartColumnNumber )
1410
+ . FirstOrDefault ( ) ;
1411
+ if ( startToken == null )
1412
+ {
1413
+ offsets [ k ] = GetDefaultTuple ( ) ;
1414
+ continue ;
1415
+ }
1416
+ var endToken = Tokens . Where ( x
1417
+ => x . Extent . EndLineNumber == ext . EndLineNumber
1418
+ && x . Extent . EndColumnNumber == ext . EndColumnNumber )
1419
+ . FirstOrDefault ( ) ;
1420
+ if ( endToken == null )
1421
+ {
1422
+ offsets [ k ] = GetDefaultTuple ( ) ;
1423
+ continue ;
1424
+ }
1425
+ offsets [ k ] = GetTuple ( startToken . Extent . StartOffset , endToken . Extent . EndOffset ) ;
1426
+ }
1427
+ else
1428
+ {
1429
+ // Extent has valid offsets
1430
+ offsets [ k ] = GetTuple ( ext . StartOffset , ext . EndOffset ) ;
1431
+ }
1432
+ }
1433
+ return offsets ;
1434
+ }
1435
+
1381
1436
public static string [ ] ProcessCustomRulePaths ( string [ ] rulePaths , SessionState sessionState , bool recurse = false )
1382
1437
{
1383
1438
//if directory is given, list all the psd1 files
0 commit comments