3
3
//! Example checks are:
4
4
//!
5
5
//! * No lines over 100 characters.
6
+ //! * No files with over 3000 lines.
6
7
//! * No tabs.
7
8
//! * No trailing whitespace.
8
9
//! * No CR characters.
@@ -18,6 +19,8 @@ use std::path::Path;
18
19
19
20
const COLS : usize = 100 ;
20
21
22
+ const LINES : usize = 3000 ;
23
+
21
24
const UNEXPLAINED_IGNORE_DOCTEST_INFO : & str = r#"unexplained "```ignore" doctest; try one:
22
25
23
26
* make the test actually pass, by adding necessary imports and declarations, or
@@ -139,19 +142,21 @@ pub fn check(path: &Path, bad: &mut bool) {
139
142
140
143
let mut skip_cr = contains_ignore_directive ( & contents, "cr" ) ;
141
144
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" ) ;
143
147
let mut skip_end_whitespace = contains_ignore_directive ( & contents, "end-whitespace" ) ;
144
148
let mut skip_copyright = contains_ignore_directive ( & contents, "copyright" ) ;
145
149
let mut leading_new_lines = false ;
146
150
let mut trailing_new_lines = 0 ;
151
+ let mut lines = 0 ;
147
152
for ( i, line) in contents. split ( '\n' ) . enumerate ( ) {
148
153
let mut err = |msg : & str | {
149
154
tidy_error ! ( bad, "{}:{}: {}" , file. display( ) , i + 1 , msg) ;
150
155
} ;
151
156
if line. chars ( ) . count ( ) > COLS && !long_line_is_ok ( line) {
152
157
suppressible_tidy_err ! (
153
158
err,
154
- skip_length ,
159
+ skip_line_length ,
155
160
& format!( "line longer than {} chars" , COLS )
156
161
) ;
157
162
}
@@ -197,6 +202,7 @@ pub fn check(path: &Path, bad: &mut bool) {
197
202
} else {
198
203
trailing_new_lines = 0 ;
199
204
}
205
+ lines = i;
200
206
}
201
207
if leading_new_lines {
202
208
tidy_error ! ( bad, "{}: leading newline" , file. display( ) ) ;
@@ -206,16 +212,22 @@ pub fn check(path: &Path, bad: &mut bool) {
206
212
1 => { }
207
213
n => tidy_error ! ( bad, "{}: too many trailing newlines ({})" , file. display( ) , n) ,
208
214
} ;
215
+ if !skip_file_length && lines > LINES {
216
+ tidy_error ! ( bad, "{}: too many lines ({})" , file. display( ) , lines) ;
217
+ }
209
218
210
219
if let Directive :: Ignore ( false ) = skip_cr {
211
220
tidy_error ! ( bad, "{}: ignoring CR characters unnecessarily" , file. display( ) ) ;
212
221
}
213
222
if let Directive :: Ignore ( false ) = skip_tab {
214
223
tidy_error ! ( bad, "{}: ignoring tab characters unnecessarily" , file. display( ) ) ;
215
224
}
216
- if let Directive :: Ignore ( false ) = skip_length {
225
+ if let Directive :: Ignore ( false ) = skip_line_length {
217
226
tidy_error ! ( bad, "{}: ignoring line length unnecessarily" , file. display( ) ) ;
218
227
}
228
+ if let Directive :: Ignore ( false ) = skip_file_length {
229
+ tidy_error ! ( bad, "{}: ignoring file length unnecessarily" , file. display( ) ) ;
230
+ }
219
231
if let Directive :: Ignore ( false ) = skip_end_whitespace {
220
232
tidy_error ! ( bad, "{}: ignoring trailing whitespace unnecessarily" , file. display( ) ) ;
221
233
}
0 commit comments