33//! Example checks are:
44//!
55//! * No lines over 100 characters.
6+ //! * No files with over 3000 lines.
67//! * No tabs.
78//! * No trailing whitespace.
89//! * No CR characters.
@@ -18,6 +19,8 @@ use std::path::Path;
1819
1920const COLS : usize = 100 ;
2021
22+ const LINES : usize = 3000 ;
23+
2124const UNEXPLAINED_IGNORE_DOCTEST_INFO : & str = r#"unexplained "```ignore" doctest; try one:
2225
2326* make the test actually pass, by adding necessary imports and declarations, or
@@ -139,19 +142,21 @@ pub fn check(path: &Path, bad: &mut bool) {
139142
140143 let mut skip_cr = contains_ignore_directive ( & contents, "cr" ) ;
141144 let mut skip_tab = contains_ignore_directive ( & contents, "tab" ) ;
142- let mut skip_length = contains_ignore_directive ( & contents, "linelength" ) ;
145+ let mut skip_line_length = contains_ignore_directive ( & contents, "linelength" ) ;
146+ let mut skip_file_length = contains_ignore_directive ( & contents, "filelength" ) ;
143147 let mut skip_end_whitespace = contains_ignore_directive ( & contents, "end-whitespace" ) ;
144148 let mut skip_copyright = contains_ignore_directive ( & contents, "copyright" ) ;
145149 let mut leading_new_lines = false ;
146150 let mut trailing_new_lines = 0 ;
151+ let mut lines = 0 ;
147152 for ( i, line) in contents. split ( '\n' ) . enumerate ( ) {
148153 let mut err = |msg : & str | {
149154 tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
150155 } ;
151156 if line. chars ( ) . count ( ) > COLS && !long_line_is_ok ( line) {
152157 suppressible_tidy_err ! (
153158 err,
154- skip_length ,
159+ skip_line_length ,
155160 & format!( "line longer than {} chars" , COLS )
156161 ) ;
157162 }
@@ -197,6 +202,7 @@ pub fn check(path: &Path, bad: &mut bool) {
197202 } else {
198203 trailing_new_lines = 0 ;
199204 }
205+ lines = i;
200206 }
201207 if leading_new_lines {
202208 tidy_error ! ( bad, "{}: leading newline" , file. display( ) ) ;
@@ -206,16 +212,22 @@ pub fn check(path: &Path, bad: &mut bool) {
206212 1 => { }
207213 n => tidy_error ! ( bad, "{}: too many trailing newlines ({})" , file. display( ) , n) ,
208214 } ;
215+ if !skip_file_length && lines > LINES {
216+ tidy_error ! ( bad, "{}: too many lines ({})" , file. display( ) , lines) ;
217+ }
209218
210219 if let Directive :: Ignore ( false ) = skip_cr {
211220 tidy_error ! ( bad, "{}: ignoring CR characters unnecessarily" , file. display( ) ) ;
212221 }
213222 if let Directive :: Ignore ( false ) = skip_tab {
214223 tidy_error ! ( bad, "{}: ignoring tab characters unnecessarily" , file. display( ) ) ;
215224 }
216- if let Directive :: Ignore ( false ) = skip_length {
225+ if let Directive :: Ignore ( false ) = skip_line_length {
217226 tidy_error ! ( bad, "{}: ignoring line length unnecessarily" , file. display( ) ) ;
218227 }
228+ if let Directive :: Ignore ( false ) = skip_file_length {
229+ tidy_error ! ( bad, "{}: ignoring file length unnecessarily" , file. display( ) ) ;
230+ }
219231 if let Directive :: Ignore ( false ) = skip_end_whitespace {
220232 tidy_error ! ( bad, "{}: ignoring trailing whitespace unnecessarily" , file. display( ) ) ;
221233 }
0 commit comments