@@ -612,7 +612,7 @@ public bool HasSpecialVars(string varName)
612
612
/// </summary>
613
613
/// <param name="ast"></param>
614
614
/// <returns></returns>
615
- public Dictionary < string , LinkedList < Tuple < int , int > > > GetRuleSuppression ( Ast ast )
615
+ public Dictionary < string , List < RuleSuppression > > GetRuleSuppression ( Ast ast )
616
616
{
617
617
List < RuleSuppression > ruleSuppressionList = new List < RuleSuppression > ( ) ;
618
618
@@ -632,39 +632,18 @@ public Dictionary<string, LinkedList<Tuple<int, int>>> GetRuleSuppression(Ast as
632
632
ruleSuppressionList . AddRange ( GetSuppressionsClass ( typeAst ) ) ;
633
633
}
634
634
635
- Dictionary < string , LinkedList < Tuple < int , int > > > results = new Dictionary < string , LinkedList < Tuple < int , int > > > ( StringComparer . OrdinalIgnoreCase ) ;
636
- ruleSuppressionList . Sort ( ( item , item2 ) => item . StartOffSet . CompareTo ( item2 . StartOffSet ) ) ;
635
+ Dictionary < string , List < RuleSuppression > > results = new Dictionary < string , List < RuleSuppression > > ( StringComparer . OrdinalIgnoreCase ) ;
636
+ ruleSuppressionList . Sort ( ( item , item2 ) => item . StartOffset . CompareTo ( item2 . StartOffset ) ) ;
637
637
638
638
foreach ( RuleSuppression ruleSuppression in ruleSuppressionList )
639
639
{
640
640
if ( ! results . ContainsKey ( ruleSuppression . RuleName ) )
641
641
{
642
- LinkedList < Tuple < int , int > > intervals = new LinkedList < Tuple < int , int > > ( ) ;
643
- intervals . AddLast ( Tuple . Create ( ruleSuppression . StartOffSet , ruleSuppression . EndOffset ) ) ;
644
- results . Add ( ruleSuppression . RuleName , intervals ) ;
645
- }
646
- else
647
- {
648
- LinkedList < Tuple < int , int > > intervals = results [ ruleSuppression . RuleName ] ;
649
- int previousEnd = intervals . Last . Value . Item2 ;
650
-
651
- // proccess the intervals so they do not overlap and is sorted in order
652
- if ( ruleSuppression . StartOffSet <= previousEnd )
653
- {
654
- if ( ruleSuppression . EndOffset <= previousEnd )
655
- {
656
- continue ;
657
- }
658
- else
659
- {
660
- intervals . Last . Value = Tuple . Create ( intervals . Last . Value . Item1 , ruleSuppression . EndOffset ) ;
661
- }
662
- }
663
- else
664
- {
665
- intervals . AddLast ( Tuple . Create ( ruleSuppression . StartOffSet , ruleSuppression . EndOffset ) ) ;
666
- }
642
+ List < RuleSuppression > ruleSuppressions = new List < RuleSuppression > ( ) ;
643
+ results . Add ( ruleSuppression . RuleName , ruleSuppressions ) ;
667
644
}
645
+
646
+ results [ ruleSuppression . RuleName ] . Add ( ruleSuppression ) ;
668
647
}
669
648
670
649
return results ;
@@ -727,59 +706,62 @@ internal List<RuleSuppression> GetSuppressionsClass(TypeDefinitionAst typeAst)
727
706
/// </summary>
728
707
/// <param name="ruleSuppressions"></param>
729
708
/// <param name="diagnostics"></param>
730
- public List < DiagnosticRecord > SuppressRule ( string ruleName , Dictionary < string , LinkedList < Tuple < int , int > > > ruleSuppressions , List < DiagnosticRecord > diagnostics )
709
+ public List < DiagnosticRecord > SuppressRule ( string ruleName , Dictionary < string , List < RuleSuppression > > ruleSuppressionsDict , List < DiagnosticRecord > diagnostics )
731
710
{
732
711
List < DiagnosticRecord > results = new List < DiagnosticRecord > ( ) ;
733
- if ( ! ruleSuppressions . ContainsKey ( ruleName ) || diagnostics . Count == 0 )
712
+
713
+ if ( ! ruleSuppressionsDict . ContainsKey ( ruleName ) || diagnostics . Count == 0 )
734
714
{
735
715
return diagnostics ;
736
716
}
737
717
738
- LinkedList < Tuple < int , int > > intervals = ruleSuppressions [ ruleName ] ;
718
+ List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
739
719
740
- if ( intervals . Count == 0 )
720
+ if ( ruleSuppressions . Count == 0 )
741
721
{
742
722
return diagnostics ;
743
723
}
744
724
745
725
int recordIndex = 0 ;
726
+ int ruleSuppressionIndex = 0 ;
746
727
DiagnosticRecord record = diagnostics . First ( ) ;
747
- LinkedListNode < Tuple < int , int > > interval = intervals . First ;
728
+ RuleSuppression ruleSuppression = ruleSuppressions . First ( ) ;
748
729
749
730
while ( recordIndex < diagnostics . Count )
750
731
{
751
- // the record precedes the interval so don't apply the suppression
752
- if ( record . Extent . StartOffset < interval . Value . Item1 )
732
+ // the record precedes the rule suppression so don't apply the suppression
733
+ if ( record . Extent . StartOffset < ruleSuppression . StartOffset )
753
734
{
754
735
results . Add ( record ) ;
755
- recordIndex += 1 ;
756
-
757
- if ( recordIndex == diagnostics . Count )
758
- {
759
- break ;
760
- }
761
- else
762
- {
763
- // move on to the next record
764
- record = diagnostics [ recordIndex ] ;
765
- continue ;
766
- }
767
736
}
768
-
769
- // end of the rule suppression is less than the record start offset so move on to next interval
770
- if ( interval . Value . Item2 < record . Extent . StartOffset )
737
+ // end of the rule suppression is less than the record start offset so move on to next rule suppression
738
+ else if ( ruleSuppression . EndOffset < record . Extent . StartOffset )
771
739
{
772
- interval = interval . Next ;
740
+ ruleSuppressionIndex += 1 ;
773
741
774
- if ( interval == null )
742
+ if ( ruleSuppressionIndex == ruleSuppressions . Count )
775
743
{
776
744
break ;
777
745
}
778
746
747
+ ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
748
+
779
749
continue ;
780
750
}
751
+ // at this point, the record is inside the interval
752
+ else
753
+ {
754
+ // if the rule suppression id from the rule suppression is not null and the one from diagnostic record is not null
755
+ // and they are they are not the same then we cannot ignore the record
756
+ if ( ! string . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && ! string . IsNullOrWhiteSpace ( record . RuleSuppressionID )
757
+ && ! string . Equals ( ruleSuppression . RuleSuppressionID , record . RuleSuppressionID , StringComparison . OrdinalIgnoreCase ) )
758
+ {
759
+ results . Add ( record ) ;
760
+ }
761
+ // otherwise, we ignore the record, move on to the next.
762
+ }
781
763
782
- // here the record is inside the interval so we don't add it to the result
764
+ // important assumption: this point is reached only if we want to move to the next record
783
765
recordIndex += 1 ;
784
766
785
767
if ( recordIndex == diagnostics . Count )
0 commit comments