-
Notifications
You must be signed in to change notification settings - Fork 1.6k
/
Copy pathmain.rs
358 lines (345 loc) · 11.7 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
#![feature(rustc_private)]
// warn on lints, that are included in `rust-lang/rust`s bootstrap
#![warn(rust_2018_idioms, unused_lifetimes)]
use clap::{Args, Parser, Subcommand};
use clippy_dev::{dogfood, fmt, lint, new_lint, release, serve, setup, sync, update_lints, utils};
use std::convert::Infallible;
fn main() {
let dev = Dev::parse();
match dev.command {
DevCommand::Bless => {
eprintln!("use `cargo bless` to automatically replace `.stderr` and `.fixed` files as tests are being run");
},
DevCommand::Dogfood {
fix,
allow_dirty,
allow_staged,
} => dogfood::dogfood(fix, allow_dirty, allow_staged),
DevCommand::Fmt { check, verbose } => fmt::run(check, verbose),
DevCommand::UpdateLints { print_only, check } => {
if print_only {
update_lints::print_lints();
} else if check {
update_lints::update(utils::UpdateMode::Check);
} else {
update_lints::update(utils::UpdateMode::Change);
}
},
DevCommand::NewLint {
pass,
name,
category,
r#type,
msrv,
} => match new_lint::create(&pass, &name, &category, r#type.as_deref(), msrv) {
Ok(()) => update_lints::update(utils::UpdateMode::Change),
Err(e) => eprintln!("Unable to create lint: {e}"),
},
DevCommand::Setup(SetupCommand { subcommand }) => match subcommand {
SetupSubcommand::Intellij { remove, repo_path } => {
if remove {
setup::intellij::remove_rustc_src();
} else {
setup::intellij::setup_rustc_src(&repo_path);
}
},
SetupSubcommand::GitHook { remove, force_override } => {
if remove {
setup::git_hook::remove_hook();
} else {
setup::git_hook::install_hook(force_override);
}
},
SetupSubcommand::Toolchain { force, release, name } => setup::toolchain::create(force, release, &name),
SetupSubcommand::VscodeTasks { remove, force_override } => {
if remove {
setup::vscode::remove_tasks();
} else {
setup::vscode::install_tasks(force_override);
}
},
},
DevCommand::Remove(RemoveCommand { subcommand }) => match subcommand {
RemoveSubcommand::Intellij => setup::intellij::remove_rustc_src(),
RemoveSubcommand::GitHook => setup::git_hook::remove_hook(),
RemoveSubcommand::VscodeTasks => setup::vscode::remove_tasks(),
},
DevCommand::Serve { port, lint } => serve::run(port, lint),
DevCommand::Lint { path, args } => lint::run(&path, args.iter()),
DevCommand::RenameLint {
old_name,
new_name,
uplift,
} => update_lints::rename(&old_name, new_name.as_ref().unwrap_or(&old_name), uplift),
DevCommand::Deprecate { name, reason } => update_lints::deprecate(&name, &reason),
DevCommand::Sync(SyncCommand { subcommand }) => match subcommand {
SyncSubcommand::Pull => sync::rustc_pull(),
SyncSubcommand::Push {
repo_path,
user,
branch,
force,
} => sync::rustc_push(repo_path, &user, &branch, force),
},
DevCommand::Release(ReleaseCommand { subcommand }) => match subcommand {
ReleaseSubcommand::BumpVersion => release::bump_version(),
ReleaseSubcommand::Commit { repo_path, branch } => release::rustc_clippy_commit(repo_path, branch),
},
}
}
#[derive(Parser)]
#[command(name = "dev", about)]
struct Dev {
#[command(subcommand)]
command: DevCommand,
}
#[derive(Subcommand)]
enum DevCommand {
/// Bless the test output changes
Bless,
/// Runs the dogfood test
Dogfood {
#[arg(long)]
/// Apply the suggestions when possible
fix: bool,
#[arg(long, requires = "fix")]
/// Fix code even if the working directory has changes
allow_dirty: bool,
#[arg(long, requires = "fix")]
/// Fix code even if the working directory has staged changes
allow_staged: bool,
},
/// Run rustfmt on all projects and tests
Fmt {
#[arg(long)]
/// Use the rustfmt --check option
check: bool,
#[arg(short, long)]
/// Echo commands run
verbose: bool,
},
#[command(name = "update_lints")]
/// Updates lint registration and information from the source code
///
/// Makes sure that: {n}
/// * the lint count in README.md is correct {n}
/// * the changelog contains markdown link references at the bottom {n}
/// * all lint groups include the correct lints {n}
/// * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod` {n}
/// * all lints are registered in the lint store
UpdateLints {
#[arg(long)]
/// Print a table of lints to STDOUT
///
/// This does not include deprecated and internal lints. (Does not modify any files)
print_only: bool,
#[arg(long)]
/// Checks that `cargo dev update_lints` has been run. Used on CI.
check: bool,
},
#[command(name = "new_lint")]
/// Create a new lint and run `cargo dev update_lints`
NewLint {
#[arg(short, long, value_parser = ["early", "late"], conflicts_with = "type", default_value = "late")]
/// Specify whether the lint runs during the early or late pass
pass: String,
#[arg(
short,
long,
value_parser = |name: &str| Ok::<_, Infallible>(name.replace('-', "_")),
)]
/// Name of the new lint in snake case, ex: `fn_too_long`
name: String,
#[arg(
short,
long,
value_parser = [
"style",
"correctness",
"suspicious",
"complexity",
"perf",
"pedantic",
"restriction",
"cargo",
"nursery",
"internal",
],
default_value = "nursery",
)]
/// What category the lint belongs to
category: String,
#[arg(long)]
/// What directory the lint belongs in
r#type: Option<String>,
#[arg(long)]
/// Add MSRV config code to the lint
msrv: bool,
},
/// Support for setting up your personal development environment
Setup(SetupCommand),
/// Support for removing changes done by the setup command
Remove(RemoveCommand),
/// Launch a local 'ALL the Clippy Lints' website in a browser
Serve {
#[arg(short, long, default_value = "8000")]
/// Local port for the http server
port: u16,
#[arg(long)]
/// Which lint's page to load initially (optional)
lint: Option<String>,
},
#[allow(clippy::doc_markdown)]
/// Manually run clippy on a file or package
///
/// ## Examples
///
/// Lint a single file: {n}
/// cargo dev lint tests/ui/attrs.rs
///
/// Lint a package directory: {n}
/// cargo dev lint tests/ui-cargo/wildcard_dependencies/fail {n}
/// cargo dev lint ~/my-project
///
/// Run rustfix: {n}
/// cargo dev lint ~/my-project -- --fix
///
/// Set lint levels: {n}
/// cargo dev lint file.rs -- -W clippy::pedantic {n}
/// cargo dev lint ~/my-project -- -- -W clippy::pedantic
Lint {
/// The path to a file or package directory to lint
path: String,
/// Pass extra arguments to cargo/clippy-driver
args: Vec<String>,
},
#[command(name = "rename_lint")]
/// Rename a lint
RenameLint {
/// The name of the lint to rename
old_name: String,
#[arg(required_unless_present = "uplift")]
/// The new name of the lint
new_name: Option<String>,
#[arg(long)]
/// This lint will be uplifted into rustc
uplift: bool,
},
/// Deprecate the given lint
Deprecate {
/// The name of the lint to deprecate
name: String,
#[arg(long, short)]
/// The reason for deprecation
reason: String,
},
/// Sync between the rust repo and the Clippy repo
Sync(SyncCommand),
/// Manage Clippy releases
Release(ReleaseCommand),
}
#[derive(Args)]
struct SetupCommand {
#[command(subcommand)]
subcommand: SetupSubcommand,
}
#[derive(Subcommand)]
enum SetupSubcommand {
/// Alter dependencies so Intellij Rust can find rustc internals
Intellij {
#[arg(long)]
/// Remove the dependencies added with 'cargo dev setup intellij'
remove: bool,
#[arg(long, short, conflicts_with = "remove")]
/// The path to a rustc repo that will be used for setting the dependencies
repo_path: String,
},
/// Add a pre-commit git hook that formats your code to make it look pretty
GitHook {
#[arg(long)]
/// Remove the pre-commit hook added with 'cargo dev setup git-hook'
remove: bool,
#[arg(long, short)]
/// Forces the override of an existing git pre-commit hook
force_override: bool,
},
/// Install a rustup toolchain pointing to the local clippy build
Toolchain {
#[arg(long, short)]
/// Override an existing toolchain
force: bool,
#[arg(long, short)]
/// Point to --release clippy binary
release: bool,
#[arg(long, default_value = "clippy")]
/// Name of the toolchain
name: String,
},
/// Add several tasks to vscode for formatting, validation and testing
VscodeTasks {
#[arg(long)]
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
remove: bool,
#[arg(long, short)]
/// Forces the override of existing vscode tasks
force_override: bool,
},
}
#[derive(Args)]
struct RemoveCommand {
#[command(subcommand)]
subcommand: RemoveSubcommand,
}
#[derive(Subcommand)]
enum RemoveSubcommand {
/// Remove the dependencies added with 'cargo dev setup intellij'
Intellij,
/// Remove the pre-commit git hook
GitHook,
/// Remove the tasks added with 'cargo dev setup vscode-tasks'
VscodeTasks,
}
#[derive(Args)]
struct SyncCommand {
#[command(subcommand)]
subcommand: SyncSubcommand,
}
#[derive(Subcommand)]
enum SyncSubcommand {
/// Pull changes from rustc and update the toolchain
Pull,
/// Push changes to rustc
Push {
/// The path to a rustc repo that will be used for pushing changes
repo_path: String,
#[arg(long)]
/// The GitHub username to use for pushing changes
user: String,
#[arg(long, short, default_value = "clippy-subtree-update")]
/// The branch to push to
///
/// This is mostly for experimentation and usually the default should be used.
branch: String,
#[arg(long, short)]
/// Force push changes
force: bool,
},
}
#[derive(Args)]
struct ReleaseCommand {
#[command(subcommand)]
subcommand: ReleaseSubcommand,
}
#[derive(Subcommand)]
enum ReleaseSubcommand {
#[command(name = "bump_version")]
/// Bump the version in the Cargo.toml files
BumpVersion,
/// Print the Clippy commit in the rustc repo for the specified branch
Commit {
/// The path to a rustc repo to look for the commit
repo_path: String,
/// For which branch to print the commit
branch: release::Branch,
},
}