@@ -716,25 +716,28 @@ 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.
720
+ /// Returns a list of suppressed records as well as the ones that are not suppressed
720
721
/// </summary>
721
722
/// <param name="ruleSuppressions"></param>
722
723
/// <param name="diagnostics"></param>
723
- public List < DiagnosticRecord > SuppressRule ( string ruleName , Dictionary < string , List < RuleSuppression > > ruleSuppressionsDict , List < DiagnosticRecord > diagnostics )
724
+ public Tuple < List < SuppressedRecord > , List < DiagnosticRecord > > SuppressRule ( string ruleName , Dictionary < string , List < RuleSuppression > > ruleSuppressionsDict , List < DiagnosticRecord > diagnostics )
724
725
{
725
- List < DiagnosticRecord > results = new List < DiagnosticRecord > ( ) ;
726
+ List < SuppressedRecord > suppressedRecords = new List < SuppressedRecord > ( ) ;
727
+ List < DiagnosticRecord > unSuppressedRecords = new List < DiagnosticRecord > ( ) ;
728
+ Tuple < List < SuppressedRecord > , List < DiagnosticRecord > > result = Tuple . Create ( suppressedRecords , unSuppressedRecords ) ;
726
729
727
730
if ( ruleSuppressionsDict == null || ! ruleSuppressionsDict . ContainsKey ( ruleName )
728
731
|| diagnostics == null || diagnostics . Count == 0 )
729
732
{
730
- return diagnostics ;
733
+ return result ;
731
734
}
732
735
733
736
List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
734
737
735
738
if ( ruleSuppressions . Count == 0 )
736
739
{
737
- return diagnostics ;
740
+ return result ;
738
741
}
739
742
740
743
int recordIndex = 0 ;
@@ -760,46 +763,54 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
760
763
continue ;
761
764
}
762
765
763
- // the record precedes the rule suppression so don't apply the suppression
764
- if ( record . Extent . StartOffset < ruleSuppression . StartOffset )
765
- {
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 )
766
+ // if the record precedes the rule suppression then we don't apply the suppression
767
+ // so we check that start of record is greater than start of suppression
768
+ if ( record . Extent . StartOffset >= ruleSuppression . StartOffset )
770
769
{
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 )
770
+ // end of the rule suppression is less than the record start offset so move on to next rule suppression
771
+ if ( ruleSuppression . EndOffset < record . Extent . StartOffset )
775
772
{
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
- }
773
+ ruleSuppressionIndex += 1 ;
780
774
781
- if ( ruleSuppressionIndex == ruleSuppressions . Count )
782
- {
783
- break ;
784
- }
775
+ // If we cannot found any error but the rulesuppression has a rulesuppressionid then it must be used wrongly
776
+ if ( ! String . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && suppressionCount == 0 )
777
+ {
778
+ ruleSuppression . Error = String . Format ( CultureInfo . CurrentCulture , Strings . RuleSuppressionErrorFormat , ruleSuppression . StartAttributeLine ,
779
+ System . IO . Path . GetFileName ( record . Extent . File ) , String . Format ( Strings . RuleSuppressionIDError , ruleSuppression . RuleSuppressionID ) ) ;
780
+ Helper . Instance . MyCmdlet . WriteError ( new ErrorRecord ( new ArgumentException ( ruleSuppression . Error ) , ruleSuppression . Error , ErrorCategory . InvalidArgument , ruleSuppression ) ) ;
781
+ }
785
782
786
- ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
787
- suppressionCount = 0 ;
783
+ if ( ruleSuppressionIndex == ruleSuppressions . Count )
784
+ {
785
+ break ;
786
+ }
788
787
789
- continue ;
788
+ ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
789
+ suppressionCount = 0 ;
790
+
791
+ continue ;
792
+ }
793
+ // at this point, the record is inside the interval
794
+ else
795
+ {
796
+ // if the rule suppression id from the rule suppression is not null and the one from diagnostic record is not null
797
+ // and they are they are not the same then we cannot ignore the record
798
+ if ( ! string . IsNullOrWhiteSpace ( ruleSuppression . RuleSuppressionID ) && ! string . IsNullOrWhiteSpace ( record . RuleSuppressionID )
799
+ && ! string . Equals ( ruleSuppression . RuleSuppressionID , record . RuleSuppressionID , StringComparison . OrdinalIgnoreCase ) )
800
+ {
801
+ suppressionCount -= 1 ;
802
+ unSuppressedRecords . Add ( record ) ;
803
+ }
804
+ // otherwise, we suppress the record, move on to the next.
805
+ else
806
+ {
807
+ suppressedRecords . Add ( new SuppressedRecord ( record , ruleSuppression ) ) ;
808
+ }
809
+ }
790
810
}
791
- // at this point, the record is inside the interval
792
811
else
793
812
{
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 ) )
798
- {
799
- results . Add ( record ) ;
800
- suppressionCount -= 1 ;
801
- }
802
- // otherwise, we ignore the record, move on to the next.
813
+ unSuppressedRecords . Add ( record ) ;
803
814
}
804
815
805
816
// important assumption: this point is reached only if we want to move to the next record
@@ -822,14 +833,13 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
822
833
record = diagnostics [ recordIndex ] ;
823
834
}
824
835
825
- // Add all unprocessed records to results
826
836
while ( recordIndex < diagnostics . Count )
827
837
{
828
- results . Add ( diagnostics [ recordIndex ] ) ;
838
+ unSuppressedRecords . Add ( diagnostics [ recordIndex ] ) ;
829
839
recordIndex += 1 ;
830
840
}
831
841
832
- return results ;
842
+ return result ;
833
843
}
834
844
835
845
#endregion
@@ -918,15 +928,6 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
918
928
return null ;
919
929
}
920
930
921
- /// <summary>
922
- /// Do nothing
923
- /// </summary>
924
- /// <param name="baseCtorInvokeMemberExpressionAst"></param>
925
- /// <returns></returns>
926
- public object VisitBaseCtorInvokeMemberExpression ( BaseCtorInvokeMemberExpressionAst baseCtorInvokeMemberExpressionAst )
927
- {
928
- return null ;
929
- }
930
931
931
932
/// <summary>
932
933
/// Do nothing
0 commit comments