File tree 3 files changed +66
-2
lines changed
3 files changed +66
-2
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ export CARGO_TARGET_DIR=`pwd`/target/
23
23
24
24
# Perform various checks for lint registration
25
25
./util/dev update_lints --check
26
+ ./util/dev --limit-stderr-length
26
27
cargo +nightly fmt --all -- --check
27
28
28
29
# Check running clippy-driver without cargo
Original file line number Diff line number Diff line change @@ -2,8 +2,9 @@ extern crate clap;
2
2
extern crate clippy_dev;
3
3
extern crate regex;
4
4
5
- use clap:: { App , AppSettings , Arg , SubCommand } ;
5
+ use clap:: { App , Arg , SubCommand } ;
6
6
use clippy_dev:: * ;
7
+ mod stderr_length_check;
7
8
8
9
#[ derive( PartialEq ) ]
9
10
enum UpdateMode {
@@ -13,7 +14,6 @@ enum UpdateMode {
13
14
14
15
fn main ( ) {
15
16
let matches = App :: new ( "Clippy developer tooling" )
16
- . setting ( AppSettings :: SubcommandRequiredElseHelp )
17
17
. subcommand (
18
18
SubCommand :: with_name ( "update_lints" )
19
19
. about ( "Updates lint registration and information from the source code" )
@@ -36,8 +36,16 @@ fn main() {
36
36
. help ( "Checks that util/dev update_lints has been run. Used on CI." ) ,
37
37
) ,
38
38
)
39
+ . arg (
40
+ Arg :: with_name ( "limit-stderr-length" )
41
+ . long ( "limit-stderr-length" )
42
+ . help ( "Ensures that stderr files do not grow longer than a certain amount of lines." ) ,
43
+ )
39
44
. get_matches ( ) ;
40
45
46
+ if matches. is_present ( "limit-stderr-length" ) {
47
+ stderr_length_check:: check ( ) ;
48
+ }
41
49
if let Some ( matches) = matches. subcommand_matches ( "update_lints" ) {
42
50
if matches. is_present ( "print-only" ) {
43
51
print_lints ( ) ;
Original file line number Diff line number Diff line change
1
+ use std:: ffi:: OsStr ;
2
+ use walkdir:: WalkDir ;
3
+
4
+ use std:: fs:: File ;
5
+ use std:: io:: prelude:: * ;
6
+
7
+ // The maximum length allowed for stderr files.
8
+ //
9
+ // We limit this because small files are easier to deal with than bigger files.
10
+ const LIMIT : usize = 320 ;
11
+
12
+ pub fn check ( ) {
13
+ let stderr_files = stderr_files ( ) ;
14
+ let exceeding_files = exceeding_stderr_files ( stderr_files) ;
15
+
16
+ if !exceeding_files. is_empty ( ) {
17
+ println ! ( "Error: stderr files exceeding limit of {} lines:" , LIMIT ) ;
18
+ for path in exceeding_files {
19
+ println ! ( "{}" , path) ;
20
+ }
21
+ std:: process:: exit ( 1 ) ;
22
+ }
23
+ }
24
+
25
+ fn exceeding_stderr_files ( files : impl Iterator < Item = walkdir:: DirEntry > ) -> Vec < String > {
26
+ files
27
+ . filter_map ( |file| {
28
+ let path = file. path ( ) . to_str ( ) . expect ( "Could not convert path to str" ) . to_string ( ) ;
29
+ let linecount = count_linenumbers ( & path) ;
30
+ if linecount > LIMIT {
31
+ Some ( path)
32
+ } else {
33
+ None
34
+ }
35
+ } )
36
+ . collect ( )
37
+ }
38
+
39
+ fn stderr_files ( ) -> impl Iterator < Item = walkdir:: DirEntry > {
40
+ // We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
41
+ WalkDir :: new ( "../tests/ui" )
42
+ . into_iter ( )
43
+ . filter_map ( std:: result:: Result :: ok)
44
+ . filter ( |f| f. path ( ) . extension ( ) == Some ( OsStr :: new ( "stderr" ) ) )
45
+ }
46
+
47
+ fn count_linenumbers ( filepath : & str ) -> usize {
48
+ if let Ok ( mut file) = File :: open ( filepath) {
49
+ let mut content = String :: new ( ) ;
50
+ file. read_to_string ( & mut content) . expect ( "Failed to read file?" ) ;
51
+ content. lines ( ) . count ( )
52
+ } else {
53
+ 0
54
+ }
55
+ }
You can’t perform that action at this time.
0 commit comments