@@ -27,7 +27,7 @@ impl FileChecker for Typos {
2727 ) -> Result < ( ) , std:: io:: Error > {
2828 if policy. check_filenames {
2929 if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
30- for typo in typos :: check_str ( file_name, policy. tokenizer , policy . dict ) {
30+ for typo in check_str ( file_name, policy) {
3131 let msg = report:: Typo {
3232 context : Some ( report:: PathContext { path } . into ( ) ) ,
3333 buffer : std:: borrow:: Cow :: Borrowed ( file_name. as_bytes ( ) ) ,
@@ -112,7 +112,7 @@ impl FileChecker for FixTypos {
112112 if policy. check_filenames {
113113 if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
114114 let mut fixes = Vec :: new ( ) ;
115- for typo in typos :: check_str ( file_name, policy. tokenizer , policy . dict ) {
115+ for typo in check_str ( file_name, policy) {
116116 if is_fixable ( & typo) {
117117 fixes. push ( typo. into_owned ( ) ) ;
118118 } else {
@@ -190,7 +190,7 @@ impl FileChecker for DiffTypos {
190190 if policy. check_filenames {
191191 if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
192192 let mut fixes = Vec :: new ( ) ;
193- for typo in typos :: check_str ( file_name, policy. tokenizer , policy . dict ) {
193+ for typo in check_str ( file_name, policy) {
194194 if is_fixable ( & typo) {
195195 fixes. push ( typo. into_owned ( ) ) ;
196196 } else {
@@ -256,9 +256,16 @@ impl FileChecker for Identifiers {
256256 policy : & crate :: policy:: Policy ,
257257 reporter : & dyn report:: Report ,
258258 ) -> Result < ( ) , std:: io:: Error > {
259+ let mut ignores: Option < Ignores > = None ;
259260 if policy. check_filenames {
260261 if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
261262 for word in policy. tokenizer . parse_str ( file_name) {
263+ if ignores
264+ . get_or_insert_with ( || Ignores :: new ( file_name. as_bytes ( ) , policy. ignore ) )
265+ . is_ignored ( word. span ( ) )
266+ {
267+ continue ;
268+ }
262269 let msg = report:: Parse {
263270 context : Some ( report:: PathContext { path } . into ( ) ) ,
264271 kind : report:: ParseKind :: Identifier ,
@@ -275,7 +282,6 @@ impl FileChecker for Identifiers {
275282 let msg = report:: BinaryFile { path } ;
276283 reporter. report ( msg. into ( ) ) ?;
277284 } else {
278- let mut ignores: Option < Ignores > = None ;
279285 for word in policy. tokenizer . parse_bytes ( & buffer) {
280286 if ignores
281287 . get_or_insert_with ( || Ignores :: new ( & buffer, policy. ignore ) )
@@ -312,13 +318,20 @@ impl FileChecker for Words {
312318 policy : & crate :: policy:: Policy ,
313319 reporter : & dyn report:: Report ,
314320 ) -> Result < ( ) , std:: io:: Error > {
321+ let mut ignores: Option < Ignores > = None ;
315322 if policy. check_filenames {
316323 if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
317324 for word in policy
318325 . tokenizer
319326 . parse_str ( file_name)
320327 . flat_map ( |i| i. split ( ) )
321328 {
329+ if ignores
330+ . get_or_insert_with ( || Ignores :: new ( file_name. as_bytes ( ) , policy. ignore ) )
331+ . is_ignored ( word. span ( ) )
332+ {
333+ continue ;
334+ }
322335 let msg = report:: Parse {
323336 context : Some ( report:: PathContext { path } . into ( ) ) ,
324337 kind : report:: ParseKind :: Word ,
@@ -335,7 +348,6 @@ impl FileChecker for Words {
335348 let msg = report:: BinaryFile { path } ;
336349 reporter. report ( msg. into ( ) ) ?;
337350 } else {
338- let mut ignores: Option < Ignores > = None ;
339351 for word in policy
340352 . tokenizer
341353 . parse_bytes ( & buffer)
@@ -536,6 +548,19 @@ fn write_file(
536548 Ok ( ( ) )
537549}
538550
551+ fn check_str < ' a > (
552+ buffer : & ' a str ,
553+ policy : & ' a crate :: policy:: Policy < ' a , ' a , ' a > ,
554+ ) -> impl Iterator < Item = typos:: Typo < ' a > > {
555+ let mut ignores: Option < Ignores > = None ;
556+
557+ typos:: check_str ( buffer, policy. tokenizer , policy. dict ) . filter ( move |typo| {
558+ !ignores
559+ . get_or_insert_with ( || Ignores :: new ( buffer. as_bytes ( ) , policy. ignore ) )
560+ . is_ignored ( typo. span ( ) )
561+ } )
562+ }
563+
539564fn check_bytes < ' a > (
540565 buffer : & ' a [ u8 ] ,
541566 policy : & ' a crate :: policy:: Policy < ' a , ' a , ' a > ,
0 commit comments