@@ -8,6 +8,8 @@ use ruff_python_trivia::{Cursor, is_python_whitespace};
88use ruff_text_size:: { Ranged , TextLen , TextRange , TextSize , TextSlice } ;
99use smallvec:: { SmallVec , smallvec} ;
1010
11+ use crate :: checkers:: ast:: LintContext ;
12+
1113#[ derive( Clone , Debug , Eq , PartialEq ) ]
1214enum SuppressionAction {
1315 Disable ,
@@ -101,6 +103,35 @@ impl Suppressions {
101103 let mut builder = SuppressionsBuilder :: new ( source) ;
102104 builder. load_from_tokens ( tokens)
103105 }
106+
107+ /// Check reported diagnostics against the set of valid range suppressions, and remove any
108+ /// diagnostics from the context that should be suppressed by those ranges.
109+ pub ( crate ) fn filter_diagnostics ( & self , context : & mut LintContext ) {
110+ let mut ignored: Vec < usize > = vec ! [ ] ;
111+
112+ ' outer: for ( index, diagnostic) in context. iter ( ) . enumerate ( ) {
113+ let Some ( code) = diagnostic. secondary_code ( ) else {
114+ continue ;
115+ } ;
116+ let Some ( span) = diagnostic. primary_span ( ) else {
117+ continue ;
118+ } ;
119+ let Some ( range) = span. range ( ) else {
120+ continue ;
121+ } ;
122+
123+ for suppression in & self . valid {
124+ if * code == suppression. code . as_str ( ) && suppression. range . contains_range ( range) {
125+ ignored. push ( index) ;
126+ continue ' outer;
127+ }
128+ }
129+ }
130+
131+ for index in ignored. iter ( ) . rev ( ) {
132+ context. as_mut_vec ( ) . swap_remove ( * index) ;
133+ }
134+ }
104135}
105136
106137#[ derive( Default ) ]
0 commit comments