1
+ // Run clippy on a fixed set of crates and collect the warnings.
2
+ // This helps observing the impact clippy changs have on a set of real-world code.
3
+ //
4
+ // When a new lint is introduced, we can search the results for new warnings and check for false
5
+ // positives.
6
+
1
7
#![ allow( clippy:: filter_map) ]
2
8
3
9
use crate :: clippy_project_root;
4
- use serde :: { Deserialize , Serialize } ;
10
+
5
11
use std:: collections:: HashMap ;
6
12
use std:: process:: Command ;
7
13
use std:: { fs:: write, path:: PathBuf } ;
8
14
15
+ use serde:: { Deserialize , Serialize } ;
16
+
9
17
// crate data we stored in the toml, can have multiple versions.
10
18
// if so, one TomlKrate maps to several KrateSources
11
- struct TomlKrate {
19
+ struct TomlCrate {
12
20
name : String ,
13
21
versions : Vec < String > ,
14
22
}
15
23
16
24
// represents an archive we download from crates.io
17
25
#[ derive( Debug , Serialize , Deserialize , Eq , Hash , PartialEq ) ]
18
- struct KrateSource {
26
+ struct CrateSource {
19
27
name : String ,
20
28
version : String ,
21
29
}
@@ -28,22 +36,15 @@ struct CrateList {
28
36
29
37
// represents the extracted sourcecode of a crate
30
38
#[ derive( Debug ) ]
31
- struct Krate {
39
+ struct Crate {
32
40
version : String ,
33
41
name : String ,
34
42
// path to the extracted sources that clippy can check
35
43
path : PathBuf ,
36
44
}
37
45
38
- impl KrateSource {
39
- fn new ( name : & str , version : & str ) -> Self {
40
- KrateSource {
41
- version : version. into ( ) ,
42
- name : name. into ( ) ,
43
- }
44
- }
45
-
46
- fn download_and_extract ( & self ) -> Krate {
46
+ impl CrateSource {
47
+ fn download_and_extract ( & self ) -> Crate {
47
48
let extract_dir = PathBuf :: from ( "target/crater/crates" ) ;
48
49
let krate_download_dir = PathBuf :: from ( "target/crater/downloads" ) ;
49
50
@@ -80,15 +81,15 @@ impl KrateSource {
80
81
}
81
82
// crate is extracted, return a new Krate object which contains the path to the extracted
82
83
// sources that clippy can check
83
- Krate {
84
+ Crate {
84
85
version : self . version . clone ( ) ,
85
86
name : self . name . clone ( ) ,
86
87
path : extract_dir. join ( format ! ( "{}-{}/" , self . name, self . version) ) ,
87
88
}
88
89
}
89
90
}
90
91
91
- impl Krate {
92
+ impl Crate {
92
93
fn run_clippy_lints ( & self , cargo_clippy_path : & PathBuf ) -> Vec < String > {
93
94
println ! ( "Linting {} {}..." , & self . name, & self . version) ;
94
95
let cargo_clippy_path = std:: fs:: canonicalize ( cargo_clippy_path) . unwrap ( ) ;
@@ -144,32 +145,32 @@ fn build_clippy() {
144
145
. expect ( "Failed to build clippy!" ) ;
145
146
}
146
147
147
- // get a list of KrateSources we want to check from a "crater_crates.toml" file.
148
- fn read_crates ( ) -> Vec < KrateSource > {
148
+ // get a list of CrateSources we want to check from a "crater_crates.toml" file.
149
+ fn read_crates ( ) -> Vec < CrateSource > {
149
150
let toml_path = PathBuf :: from ( "clippy_dev/crater_crates.toml" ) ;
150
151
let toml_content: String =
151
152
std:: fs:: read_to_string ( & toml_path) . unwrap_or_else ( |_| panic ! ( "Failed to read {}" , toml_path. display( ) ) ) ;
152
153
let crate_list: CrateList =
153
154
toml:: from_str ( & toml_content) . unwrap_or_else ( |e| panic ! ( "Failed to parse {}: \n {}" , toml_path. display( ) , e) ) ;
154
155
// parse the hashmap of the toml file into a list of crates
155
- let tomlkrates : Vec < TomlKrate > = crate_list
156
+ let tomlcrates : Vec < TomlCrate > = crate_list
156
157
. crates
157
158
. into_iter ( )
158
- . map ( |( name, versions) | TomlKrate { name, versions } )
159
+ . map ( |( name, versions) | TomlCrate { name, versions } )
159
160
. collect ( ) ;
160
161
161
- // flatten TomlKrates into KrateSources (one TomlKrates may represent several versions of a crate =>
162
- // multiple kratesources )
163
- let mut krate_sources = Vec :: new ( ) ;
164
- tomlkrates . into_iter ( ) . for_each ( |tk| {
162
+ // flatten TomlCrates into CrateSources (one TomlCrates may represent several versions of a crate =>
163
+ // multiple Cratesources )
164
+ let mut crate_sources = Vec :: new ( ) ;
165
+ tomlcrates . into_iter ( ) . for_each ( |tk| {
165
166
tk. versions . iter ( ) . for_each ( |ver| {
166
- krate_sources . push ( KrateSource {
167
+ crate_sources . push ( CrateSource {
167
168
name : tk. name . clone ( ) ,
168
169
version : ver. to_string ( ) ,
169
170
} ) ;
170
171
} )
171
172
} ) ;
172
- krate_sources
173
+ crate_sources
173
174
}
174
175
175
176
// the main fn
0 commit comments