Skip to content

Commit 3507173

Browse files
committed
group printing
1 parent fba02d8 commit 3507173

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

src/driver.rs

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ impl rustc_driver::Callbacks for ClippyCallbacks {
112112

113113
fn describe_lints() {
114114
use lintlist::*;
115+
use std::collections::HashSet;
115116

116117
println!(
117118
"
@@ -143,49 +144,58 @@ Available lint options:
143144

144145
let scoped = |x: &str| format!("clippy::{}", x);
145146

147+
let lint_groups: HashSet<_> = lints.iter().map(|lint| lint.group).collect();
148+
146149
println!("Lint checks provided by clippy:\n");
147150
println!(" {} {:7.7} meaning", padded("name"), "default");
148151
println!(" {} {:7.7} -------", padded("----"), "-------");
149152

150-
let print_lints = |lints: Vec<&Lint>| {
153+
let print_lints = |lints: &[&Lint]| {
151154
for lint in lints {
152155
let name = lint.name.replace("_", "-");
153156
println!(" {} {:7.7} {}", padded(&scoped(&name)), "unknown", lint.desc);
154157
}
155158
println!("\n");
156159
};
157160

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();
189199

190200
// print_lint_groups(builtin_groups);
191201

@@ -295,17 +305,18 @@ pub fn main() {
295305
exit(0);
296306
}
297307

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| {
302311
args[1] == "help"
303312
&& match args[0].as_str() {
304313
"-W" | "-A" | "-D" | "-F" => true,
305314
_ => false,
306315
}
307316
})
308-
{
317+
};
318+
319+
if !wrapper_mode && should_describe_lints() {
309320
describe_lints();
310321
exit(0);
311322
}

0 commit comments

Comments
 (0)