@@ -119,6 +119,7 @@ fn contains_ignore_directive(can_contain: bool, contents: &str, check: &str) ->
119119 // Update `can_contain` when changing this
120120 if contents. contains ( & format ! ( "// ignore-tidy-{}" , check) )
121121 || contents. contains ( & format ! ( "# ignore-tidy-{}" , check) )
122+ || contents. contains ( & format ! ( "/* ignore-tidy-{} */" , check) )
122123 {
123124 Directive :: Ignore ( false )
124125 } else {
@@ -136,15 +137,37 @@ macro_rules! suppressible_tidy_err {
136137 } ;
137138}
138139
140+ pub fn is_in ( full_path : & Path , parent_folder_to_find : & str , folder_to_find : & str ) -> bool {
141+ if let Some ( parent) = full_path. parent ( ) {
142+ if parent. file_name ( ) . map_or_else (
143+ || false ,
144+ |f| {
145+ f. to_string_lossy ( ) == folder_to_find
146+ && parent
147+ . parent ( )
148+ . and_then ( |f| f. file_name ( ) )
149+ . map_or_else ( || false , |f| f == parent_folder_to_find)
150+ } ,
151+ ) {
152+ true
153+ } else {
154+ is_in ( parent, parent_folder_to_find, folder_to_find)
155+ }
156+ } else {
157+ false
158+ }
159+ }
160+
139161pub fn check ( path : & Path , bad : & mut bool ) {
140162 super :: walk ( path, & mut super :: filter_dirs, & mut |entry, contents| {
141163 let file = entry. path ( ) ;
142164 let filename = file. file_name ( ) . unwrap ( ) . to_string_lossy ( ) ;
143- let extensions = [ ".rs" , ".py" , ".js" , ".sh" , ".c" , ".cpp" , ".h" , ".md" ] ;
165+ let extensions = [ ".rs" , ".py" , ".js" , ".sh" , ".c" , ".cpp" , ".h" , ".md" , ".css" ] ;
144166 if extensions. iter ( ) . all ( |e| !filename. ends_with ( e) ) || filename. starts_with ( ".#" ) {
145167 return ;
146168 }
147169
170+ let is_style_file = filename. ends_with ( ".css" ) ;
148171 let under_rustfmt = filename. ends_with ( ".rs" ) &&
149172 // This list should ideally be sourced from rustfmt.toml but we don't want to add a toml
150173 // parser to tidy.
@@ -161,6 +184,10 @@ pub fn check(path: &Path, bad: &mut bool) {
161184 // currently), just the long error code explanation ones.
162185 return ;
163186 }
187+ if is_style_file && !is_in ( file, "src" , "librustdoc" ) {
188+ // We only check CSS files in rustdoc.
189+ return ;
190+ }
164191
165192 if contents. is_empty ( ) {
166193 tidy_error ! ( bad, "{}: empty file" , file. display( ) ) ;
@@ -172,8 +199,9 @@ pub fn check(path: &Path, bad: &mut bool) {
172199 COLS
173200 } ;
174201
175- let can_contain =
176- contents. contains ( "// ignore-tidy-" ) || contents. contains ( "# ignore-tidy-" ) ;
202+ let can_contain = contents. contains ( "// ignore-tidy-" )
203+ || contents. contains ( "# ignore-tidy-" )
204+ || contents. contains ( "/* ignore-tidy-" ) ;
177205 // Enable testing ICE's that require specific (untidy)
178206 // file formats easily eg. `issue-1234-ignore-tidy.rs`
179207 if filename. contains ( "ignore-tidy" ) {
@@ -208,12 +236,15 @@ pub fn check(path: &Path, bad: &mut bool) {
208236 & format!( "line longer than {} chars" , max_columns)
209237 ) ;
210238 }
211- if line. contains ( '\t' ) {
239+ if !is_style_file && line. contains ( '\t' ) {
212240 suppressible_tidy_err ! ( err, skip_tab, "tab character" ) ;
213241 }
214242 if line. ends_with ( ' ' ) || line. ends_with ( '\t' ) {
215243 suppressible_tidy_err ! ( err, skip_end_whitespace, "trailing whitespace" ) ;
216244 }
245+ if is_style_file && line. starts_with ( ' ' ) {
246+ err ( "CSS files use tabs for indent" ) ;
247+ }
217248 if line. contains ( '\r' ) {
218249 suppressible_tidy_err ! ( err, skip_cr, "CR character" ) ;
219250 }
0 commit comments