@@ -337,12 +337,16 @@ pub fn check(path: &Path, bad: &mut bool) {
337337 . case_insensitive ( true )
338338 . build ( )
339339 . unwrap ( ) ;
340- let style_file = Path :: new ( file ! ( ) ) ;
340+
341+ // In some cases, a style check would be triggered by its own implementation
342+ // or comments. A simple workaround is to just allowlist this file.
343+ let this_file = Path :: new ( file ! ( ) ) ;
344+
341345 walk ( path, skip, & mut |entry, contents| {
342346 let file = entry. path ( ) ;
343347 let filename = file. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
344348
345- let is_style_file = filename. ends_with ( ".css" ) ;
349+ let is_css_file = filename. ends_with ( ".css" ) ;
346350 let under_rustfmt = filename. ends_with ( ".rs" ) &&
347351 // This list should ideally be sourced from rustfmt.toml but we don't want to add a toml
348352 // parser to tidy.
@@ -405,13 +409,13 @@ pub fn check(path: &Path, bad: &mut bool) {
405409 let mut comment_block: Option < ( usize , usize ) > = None ;
406410 let is_test = file. components ( ) . any ( |c| c. as_os_str ( ) == "tests" )
407411 || file. file_stem ( ) . unwrap ( ) == "tests" ;
408- let is_style = file. ends_with ( style_file ) || style_file . ends_with ( file) ;
409- let is_style_test =
410- is_test && file. parent ( ) . unwrap ( ) . ends_with ( style_file . with_extension ( "" ) ) ;
412+ let is_this_file = file. ends_with ( this_file ) || this_file . ends_with ( file) ;
413+ let is_test_for_this_file =
414+ is_test && file. parent ( ) . unwrap ( ) . ends_with ( this_file . with_extension ( "" ) ) ;
411415 // scanning the whole file for multiple needles at once is more efficient than
412416 // executing lines times needles separate searches.
413417 let any_problematic_line =
414- !is_style && !is_style_test && problematic_regex. is_match ( contents) ;
418+ !is_this_file && !is_test_for_this_file && problematic_regex. is_match ( contents) ;
415419 for ( i, line) in contents. split ( '\n' ) . enumerate ( ) {
416420 if line. is_empty ( ) {
417421 if i == 0 {
@@ -458,19 +462,19 @@ pub fn check(path: &Path, bad: &mut bool) {
458462 "line longer than {max_columns} chars"
459463 ) ;
460464 }
461- if !is_style_file && line. contains ( '\t' ) {
465+ if !is_css_file && line. contains ( '\t' ) {
462466 suppressible_tidy_err ! ( err, skip_tab, "tab character" ) ;
463467 }
464468 if line. ends_with ( ' ' ) || line. ends_with ( '\t' ) {
465469 suppressible_tidy_err ! ( err, skip_end_whitespace, "trailing whitespace" ) ;
466470 }
467- if is_style_file && line. starts_with ( ' ' ) {
471+ if is_css_file && line. starts_with ( ' ' ) {
468472 err ( "CSS files use tabs for indent" ) ;
469473 }
470474 if line. contains ( '\r' ) {
471475 suppressible_tidy_err ! ( err, skip_cr, "CR character" ) ;
472476 }
473- if !is_style {
477+ if !is_this_file {
474478 // Allow using TODO in diagnostic suggestions by marking the
475479 // relevant line with `// ignore-tidy-todo`.
476480 if trimmed. contains ( "TODO" ) && !trimmed. contains ( "ignore-tidy-todo" ) {
0 commit comments