@@ -716,25 +716,23 @@ internal List<RuleSuppression> GetSuppressionsClass(TypeDefinitionAst typeAst)
716
716
}
717
717
718
718
/// <summary>
719
- /// Suppress the rules from the diagnostic records list and return the result
719
+ /// Suppress the rules from the diagnostic records list by attaching rule suppression to the record that is suppressed
720
720
/// </summary>
721
721
/// <param name="ruleSuppressions"></param>
722
722
/// <param name="diagnostics"></param>
723
- public List < DiagnosticRecord > SuppressRule ( string ruleName , Dictionary < string , List < RuleSuppression > > ruleSuppressionsDict , List < DiagnosticRecord > diagnostics )
723
+ public void SuppressRule ( string ruleName , Dictionary < string , List < RuleSuppression > > ruleSuppressionsDict , List < DiagnosticRecord > diagnostics )
724
724
{
725
- List < DiagnosticRecord > results = new List < DiagnosticRecord > ( ) ;
726
-
727
725
if ( ruleSuppressionsDict == null || ! ruleSuppressionsDict . ContainsKey ( ruleName )
728
726
|| diagnostics == null || diagnostics . Count == 0 )
729
727
{
730
- return diagnostics ;
728
+ return ;
731
729
}
732
730
733
731
List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
734
732
735
733
if ( ruleSuppressions . Count == 0 )
736
734
{
737
- return diagnostics ;
735
+ return ;
738
736
}
739
737
740
738
int recordIndex = 0 ;
@@ -760,46 +758,49 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
760
758
continue ;
761
759
}
762
760
763
- // the record precedes the rule suppression so don't apply the suppression
764
- if ( record . Extent . StartOffset < ruleSuppression . StartOffset )
761
+ // if the record precedes the rule suppression then we don't apply the suppression
762
+ // so we check that start of record is greater than start of suppression
763
+ if ( record . Extent . StartOffset >= ruleSuppression . StartOffset )
765
764
{
766
- results . Add ( record ) ;
767
- }
768
- // end of the rule suppression is less than the record start offset so move on to next rule suppression
769
- else if ( ruleSuppression . EndOffset < record . Extent . StartOffset )
770
- {
771
- ruleSuppressionIndex += 1 ;
772
-
773
- // If we cannot found any error but the rulesuppression has a rulesuppressionid then it must be used wrongly
774
- if ( ! String . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && suppressionCount == 0 )
765
+ // end of the rule suppression is less than the record start offset so move on to next rule suppression
766
+ if ( ruleSuppression . EndOffset < record . Extent . StartOffset )
775
767
{
776
- ruleSuppression . Error = String . Format ( CultureInfo . CurrentCulture , Strings . RuleSuppressionErrorFormat , ruleSuppression . StartAttributeLine ,
777
- System . IO . Path . GetFileName ( record . Extent . File ) , String . Format ( Strings . RuleSuppressionIDError , ruleSuppression . RuleSuppressionID ) ) ;
778
- Helper . Instance . MyCmdlet . WriteError ( new ErrorRecord ( new ArgumentException ( ruleSuppression . Error ) , ruleSuppression . Error , ErrorCategory . InvalidArgument , ruleSuppression ) ) ;
779
- }
768
+ ruleSuppressionIndex += 1 ;
780
769
781
- if ( ruleSuppressionIndex == ruleSuppressions . Count )
782
- {
783
- break ;
784
- }
770
+ // If we cannot found any error but the rulesuppression has a rulesuppressionid then it must be used wrongly
771
+ if ( ! String . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && suppressionCount == 0 )
772
+ {
773
+ ruleSuppression . Error = String . Format ( CultureInfo . CurrentCulture , Strings . RuleSuppressionErrorFormat , ruleSuppression . StartAttributeLine ,
774
+ System . IO . Path . GetFileName ( record . Extent . File ) , String . Format ( Strings . RuleSuppressionIDError , ruleSuppression . RuleSuppressionID ) ) ;
775
+ Helper . Instance . MyCmdlet . WriteError ( new ErrorRecord ( new ArgumentException ( ruleSuppression . Error ) , ruleSuppression . Error , ErrorCategory . InvalidArgument , ruleSuppression ) ) ;
776
+ }
785
777
786
- ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
787
- suppressionCount = 0 ;
778
+ if ( ruleSuppressionIndex == ruleSuppressions . Count )
779
+ {
780
+ break ;
781
+ }
788
782
789
- continue ;
790
- }
791
- // at this point, the record is inside the interval
792
- else
793
- {
794
- // if the rule suppression id from the rule suppression is not null and the one from diagnostic record is not null
795
- // and they are they are not the same then we cannot ignore the record
796
- if ( ! string . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && ! string . IsNullOrWhiteSpace ( record . RuleSuppressionID )
797
- && ! string . Equals ( ruleSuppression . RuleSuppressionID , record . RuleSuppressionID , StringComparison . OrdinalIgnoreCase ) )
783
+ ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
784
+ suppressionCount = 0 ;
785
+
786
+ continue ;
787
+ }
788
+ // at this point, the record is inside the interval
789
+ else
798
790
{
799
- results . Add ( record ) ;
800
- suppressionCount -= 1 ;
791
+ // if the rule suppression id from the rule suppression is not null and the one from diagnostic record is not null
792
+ // and they are they are not the same then we cannot ignore the record
793
+ if ( ! string . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && ! string . IsNullOrWhiteSpace ( record . RuleSuppressionID )
794
+ && ! string . Equals ( ruleSuppression . RuleSuppressionID , record . RuleSuppressionID , StringComparison . OrdinalIgnoreCase ) )
795
+ {
796
+ suppressionCount -= 1 ;
797
+ }
798
+ // otherwise, we suppress the record, move on to the next.
799
+ else
800
+ {
801
+ record . Suppression = ruleSuppression ;
802
+ }
801
803
}
802
- // otherwise, we ignore the record, move on to the next.
803
804
}
804
805
805
806
// important assumption: this point is reached only if we want to move to the next record
@@ -821,15 +822,6 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
821
822
822
823
record = diagnostics [ recordIndex ] ;
823
824
}
824
-
825
- // Add all unprocessed records to results
826
- while ( recordIndex < diagnostics . Count )
827
- {
828
- results . Add ( diagnostics [ recordIndex ] ) ;
829
- recordIndex += 1 ;
830
- }
831
-
832
- return results ;
833
825
}
834
826
835
827
#endregion
0 commit comments