@@ -112,6 +112,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
112
112
113
113
fn describe_lints ( ) {
114
114
use lintlist:: * ;
115
+ use std:: collections:: HashSet ;
115
116
116
117
println ! (
117
118
"
@@ -143,49 +144,58 @@ Available lint options:
143
144
144
145
let scoped = |x : & str | format ! ( "clippy::{}" , x) ;
145
146
147
+ let lint_groups: HashSet < _ > = lints. iter ( ) . map ( |lint| lint. group ) . collect ( ) ;
148
+
146
149
println ! ( "Lint checks provided by clippy:\n " ) ;
147
150
println ! ( " {} {:7.7} meaning" , padded( "name" ) , "default" ) ;
148
151
println ! ( " {} {:7.7} -------" , padded( "----" ) , "-------" ) ;
149
152
150
- let print_lints = |lints : Vec < & Lint > | {
153
+ let print_lints = |lints : & [ & Lint ] | {
151
154
for lint in lints {
152
155
let name = lint. name . replace ( "_" , "-" ) ;
153
156
println ! ( " {} {:7.7} {}" , padded( & scoped( & name) ) , "unknown" , lint. desc) ;
154
157
}
155
158
println ! ( "\n " ) ;
156
159
} ;
157
160
158
- print_lints ( lints) ;
159
-
160
- // let max_name_len = max("warnings".len(),
161
- // plugin_groups.iter()
162
- // .chain(&builtin_groups)
163
- // .map(|&(s, _)| s.chars().count())
164
- // .max()
165
- // .unwrap_or(0));
166
-
167
- // let padded = |x: &str| {
168
- // let mut s = " ".repeat(max_name_len - x.chars().count());
169
- // s.push_str(x);
170
- // s
171
- // };
172
-
173
- // println!("Lint groups provided by rustc:\n");
174
- // println!(" {} {}", padded("name"), "sub-lints");
175
- // println!(" {} {}", padded("----"), "---------");
176
- // println!(" {} {}", padded("warnings"), "all lints that are set to issue warnings");
177
-
178
- // let print_lint_groups = |lints: Vec<(&'static str, Vec<lint::LintId>)>| {
179
- // for (name, to) in lints {
180
- // let name = name.to_lowercase().replace("_", "-");
181
- // let desc = to.into_iter()
182
- // .map(|x| x.to_string().replace("_", "-"))
183
- // .collect::<Vec<String>>()
184
- // .join(", ");
185
- // println!(" {} {}", padded(&name), desc);
186
- // }
187
- // println!("\n");
188
- // };
161
+ print_lints ( & lints) ;
162
+
163
+ let max_name_len = std:: cmp:: max (
164
+ "warnings" . len ( ) ,
165
+ lint_groups
166
+ . iter ( )
167
+ . map ( |group| group. len ( ) )
168
+ . map ( |len| len + "clippy::" . len ( ) )
169
+ . max ( )
170
+ . unwrap_or ( 0 ) ,
171
+ ) ;
172
+
173
+ let padded = |x : & str | {
174
+ let mut s = " " . repeat ( max_name_len - x. chars ( ) . count ( ) ) ;
175
+ s. push_str ( x) ;
176
+ s
177
+ } ;
178
+
179
+ println ! ( "Lint groups provided by rustc:\n " ) ;
180
+ println ! ( " {} sub-lints" , padded( "name" ) ) ;
181
+ println ! ( " {} ---------" , padded( "----" ) ) ;
182
+ // println!(" {} all lints that are set to issue warnings", padded("warnings"));
183
+
184
+ let print_lint_groups = || {
185
+ for group in lint_groups {
186
+ let name = group. to_lowercase ( ) . replace ( "_" , "-" ) ;
187
+ let desc = lints. iter ( )
188
+ . filter ( |& lint| lint. group == group)
189
+ . map ( |lint| lint. name )
190
+ . map ( |name| name. replace ( "_" , "-" ) )
191
+ . collect :: < Vec < String > > ( )
192
+ . join ( ", " ) ;
193
+ println ! ( " {} {}" , padded( & name) , desc) ;
194
+ }
195
+ println ! ( "\n " ) ;
196
+ } ;
197
+
198
+ print_lint_groups ( ) ;
189
199
190
200
// print_lint_groups(builtin_groups);
191
201
@@ -295,17 +305,18 @@ pub fn main() {
295
305
exit ( 0 ) ;
296
306
}
297
307
298
- let args: Vec < _ > = std:: env:: args ( ) . collect ( ) ;
299
-
300
- if !wrapper_mode
301
- && args. windows ( 2 ) . any ( |args| {
308
+ let should_describe_lints = || {
309
+ let args: Vec < _ > = std:: env:: args ( ) . collect ( ) ;
310
+ args. windows ( 2 ) . any ( |args| {
302
311
args[ 1 ] == "help"
303
312
&& match args[ 0 ] . as_str ( ) {
304
313
"-W" | "-A" | "-D" | "-F" => true ,
305
314
_ => false ,
306
315
}
307
316
} )
308
- {
317
+ } ;
318
+
319
+ if !wrapper_mode && should_describe_lints ( ) {
309
320
describe_lints ( ) ;
310
321
exit ( 0 ) ;
311
322
}
0 commit comments