Skip to content

Commit 5a7f36f

Browse files
committed
initial commit for help improvements on clippy-driver
1 parent 01ab9fe commit 5a7f36f

File tree

3 files changed

+2332
-0
lines changed

3 files changed

+2332
-0
lines changed

clippy_dev/src/main.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ fn print_lints() {
8787

8888
fn update_lints(update_mode: &UpdateMode) {
8989
let lint_list: Vec<Lint> = gather_all().collect();
90+
91+
std::fs::write(
92+
"../src/lintlist.rs",
93+
&format!(
94+
"\
95+
/// Lint data parsed from the Clippy source code.
96+
#[derive(Clone, PartialEq, Debug)]
97+
pub struct Lint {{
98+
pub name: &'static str,
99+
pub group: &'static str,
100+
pub desc: &'static str,
101+
pub deprecation: Option<&'static str>,
102+
pub module: &'static str,
103+
}}
104+
105+
pub const ALL_LINTS: [Lint; {}] = {:#?};",
106+
lint_list.len(),
107+
lint_list
108+
),
109+
)
110+
.expect("can write to file");
111+
90112
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
91113
let lint_count = usable_lints.len();
92114

src/driver.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use rustc_tools_util::*;
1515
use std::path::Path;
1616
use std::process::{exit, Command};
1717

18+
mod lintlist;
19+
1820
/// If a command-line option matches `find_arg`, then apply the predicate `pred` on its value. If
1921
/// true, then return it. The parameter is assumed to be either `--arg=value` or `--arg value`.
2022
fn arg_value<'a>(
@@ -120,6 +122,40 @@ pub fn main() {
120122
exit(0);
121123
}
122124

125+
if std::env::args().any(|a| a == "--help" || a == "-h") {
126+
println!(
127+
"\
128+
Checks a package to catch common mistakes and improve your Rust code.
129+
130+
Usage:
131+
cargo clippy [options] [--] [<opts>...]
132+
133+
Common options:
134+
-h, --help Print this message
135+
-V, --version Print version info and exit
136+
137+
Other options are the same as `cargo check`.
138+
139+
To allow or deny a lint from the command line you can use `cargo clippy --`
140+
with:
141+
142+
-W --warn OPT Set lint warnings
143+
-A --allow OPT Set lint allowed
144+
-D --deny OPT Set lint denied
145+
-F --forbid OPT Set lint forbidden
146+
147+
You can use tool lints to allow or deny lints from your code, eg.:
148+
149+
#[allow(clippy::needless_lifetimes)]
150+
"
151+
);
152+
153+
for lint in &lintlist::ALL_LINTS[..] {
154+
println!("clippy::{},", lint.name);
155+
}
156+
exit(0);
157+
}
158+
123159
let mut orig_args: Vec<String> = env::args().collect();
124160

125161
// Get the sysroot, looking from most specific to this invocation to the least:

0 commit comments

Comments
 (0)