@@ -27,7 +27,7 @@ impl FileChecker for Typos {
27
27
) -> Result < ( ) , std:: io:: Error > {
28
28
if policy. check_filenames {
29
29
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) {
31
31
let msg = report:: Typo {
32
32
context : Some ( report:: PathContext { path } . into ( ) ) ,
33
33
buffer : std:: borrow:: Cow :: Borrowed ( file_name. as_bytes ( ) ) ,
@@ -112,7 +112,7 @@ impl FileChecker for FixTypos {
112
112
if policy. check_filenames {
113
113
if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
114
114
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) {
116
116
if is_fixable ( & typo) {
117
117
fixes. push ( typo. into_owned ( ) ) ;
118
118
} else {
@@ -190,7 +190,7 @@ impl FileChecker for DiffTypos {
190
190
if policy. check_filenames {
191
191
if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
192
192
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) {
194
194
if is_fixable ( & typo) {
195
195
fixes. push ( typo. into_owned ( ) ) ;
196
196
} else {
@@ -256,9 +256,16 @@ impl FileChecker for Identifiers {
256
256
policy : & crate :: policy:: Policy ,
257
257
reporter : & dyn report:: Report ,
258
258
) -> Result < ( ) , std:: io:: Error > {
259
+ let mut ignores: Option < Ignores > = None ;
259
260
if policy. check_filenames {
260
261
if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
261
262
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
+ }
262
269
let msg = report:: Parse {
263
270
context : Some ( report:: PathContext { path } . into ( ) ) ,
264
271
kind : report:: ParseKind :: Identifier ,
@@ -275,7 +282,6 @@ impl FileChecker for Identifiers {
275
282
let msg = report:: BinaryFile { path } ;
276
283
reporter. report ( msg. into ( ) ) ?;
277
284
} else {
278
- let mut ignores: Option < Ignores > = None ;
279
285
for word in policy. tokenizer . parse_bytes ( & buffer) {
280
286
if ignores
281
287
. get_or_insert_with ( || Ignores :: new ( & buffer, policy. ignore ) )
@@ -312,13 +318,20 @@ impl FileChecker for Words {
312
318
policy : & crate :: policy:: Policy ,
313
319
reporter : & dyn report:: Report ,
314
320
) -> Result < ( ) , std:: io:: Error > {
321
+ let mut ignores: Option < Ignores > = None ;
315
322
if policy. check_filenames {
316
323
if let Some ( file_name) = path. file_name ( ) . and_then ( |s| s. to_str ( ) ) {
317
324
for word in policy
318
325
. tokenizer
319
326
. parse_str ( file_name)
320
327
. flat_map ( |i| i. split ( ) )
321
328
{
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
+ }
322
335
let msg = report:: Parse {
323
336
context : Some ( report:: PathContext { path } . into ( ) ) ,
324
337
kind : report:: ParseKind :: Word ,
@@ -335,7 +348,6 @@ impl FileChecker for Words {
335
348
let msg = report:: BinaryFile { path } ;
336
349
reporter. report ( msg. into ( ) ) ?;
337
350
} else {
338
- let mut ignores: Option < Ignores > = None ;
339
351
for word in policy
340
352
. tokenizer
341
353
. parse_bytes ( & buffer)
@@ -536,6 +548,19 @@ fn write_file(
536
548
Ok ( ( ) )
537
549
}
538
550
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
+
539
564
fn check_bytes < ' a > (
540
565
buffer : & ' a [ u8 ] ,
541
566
policy : & ' a crate :: policy:: Policy < ' a , ' a , ' a > ,
0 commit comments