@@ -716,25 +716,28 @@ internal List<RuleSuppression> GetSuppressionsClass(TypeDefinitionAst typeAst)
716716 }
717717
718718 /// <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
720721 /// </summary>
721722 /// <param name="ruleSuppressions"></param>
722723 /// <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 )
724725 {
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 ) ;
726729
727730 if ( ruleSuppressionsDict == null || ! ruleSuppressionsDict . ContainsKey ( ruleName )
728731 || diagnostics == null || diagnostics . Count == 0 )
729732 {
730- return diagnostics ;
733+ return result ;
731734 }
732735
733736 List < RuleSuppression > ruleSuppressions = ruleSuppressionsDict [ ruleName ] ;
734737
735738 if ( ruleSuppressions . Count == 0 )
736739 {
737- return diagnostics ;
740+ return result ;
738741 }
739742
740743 int recordIndex = 0 ;
@@ -760,46 +763,54 @@ public List<DiagnosticRecord> SuppressRule(string ruleName, Dictionary<string, L
760763 continue ;
761764 }
762765
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 )
770769 {
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 )
775772 {
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 ;
780774
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+ }
785782
786- ruleSuppression = ruleSuppressions [ ruleSuppressionIndex ] ;
787- suppressionCount = 0 ;
783+ if ( ruleSuppressionIndex == ruleSuppressions . Count )
784+ {
785+ break ;
786+ }
788787
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+ }
790810 }
791- // at this point, the record is inside the interval
792811 else
793812 {
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 ) ;
803814 }
804815
805816 // 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
822833 record = diagnostics [ recordIndex ] ;
823834 }
824835
825- // Add all unprocessed records to results
826836 while ( recordIndex < diagnostics . Count )
827837 {
828- results . Add ( diagnostics [ recordIndex ] ) ;
838+ unSuppressedRecords . Add ( diagnostics [ recordIndex ] ) ;
829839 recordIndex += 1 ;
830840 }
831841
832- return results ;
842+ return result ;
833843 }
834844
835845 #endregion
@@ -918,15 +928,6 @@ public object VisitScriptBlock(ScriptBlockAst scriptBlockAst)
918928 return null ;
919929 }
920930
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- }
930931
931932 /// <summary>
932933 /// Do nothing
0 commit comments