2 extern crate clippy_dev;
5 use clap::{App, AppSettings, Arg, SubCommand};
15 let matches = App::new("Clippy developer tooling")
16 .setting(AppSettings::SubcommandRequiredElseHelp)
18 SubCommand::with_name("update_lints")
19 .about("Updates lint registration and information from the source code")
22 * the lint count in README.md is correct\n \
23 * the changelog contains markdown link references at the bottom\n \
24 * all lint groups include the correct lints\n \
25 * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
26 * all lints are registered in the lint store",
28 .arg(Arg::with_name("print-only").long("print-only").help(
29 "Print a table of lints to STDOUT. \
30 This does not include deprecated and internal lints. \
31 (Does not modify any files)",
34 Arg::with_name("check")
36 .help("Checks that util/dev update_lints has been run. Used on CI."),
41 if let Some(matches) = matches.subcommand_matches("update_lints") {
42 if matches.is_present("print-only") {
44 } else if matches.is_present("check") {
45 update_lints(&UpdateMode::Check);
47 update_lints(&UpdateMode::Change);
53 let lint_list = gather_all();
54 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
55 let lint_count = usable_lints.len();
56 let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
58 for (lint_group, mut lints) in grouped_by_lint_group {
59 if lint_group == "Deprecated" {
62 println!("\n## {}", lint_group);
64 lints.sort_by_key(|l| l.name.clone());
70 clippy_dev::DOCS_LINK.clone(),
77 println!("there are {} lints", lint_count);
80 fn update_lints(update_mode: &UpdateMode) {
81 let lint_list: Vec<Lint> = gather_all().collect();
82 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
83 let lint_count = usable_lints.len();
85 let mut file_change = replace_region_in_file(
87 r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
90 update_mode == &UpdateMode::Change,
93 format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
98 file_change |= replace_region_in_file(
100 "<!-- begin autogenerated links to lint list -->",
101 "<!-- end autogenerated links to lint list -->",
103 update_mode == &UpdateMode::Change,
104 || gen_changelog_lint_list(lint_list.clone()),
108 file_change |= replace_region_in_file(
109 "../clippy_lints/src/lib.rs",
110 "begin deprecated lints",
111 "end deprecated lints",
113 update_mode == &UpdateMode::Change,
114 || gen_deprecated(&lint_list),
118 file_change |= replace_region_in_file(
119 "../clippy_lints/src/lib.rs",
120 "begin lints modules",
123 update_mode == &UpdateMode::Change,
124 || gen_modules_list(lint_list.clone()),
128 // Generate lists of lints in the clippy::all lint group
129 file_change |= replace_region_in_file(
130 "../clippy_lints/src/lib.rs",
131 r#"reg.register_lint_group\("clippy::all""#,
134 update_mode == &UpdateMode::Change,
136 // clippy::all should only include the following lint groups:
137 let all_group_lints = usable_lints
141 l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
145 gen_lint_group_list(all_group_lints)
150 // Generate the list of lints for all other lint groups
151 for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
152 file_change |= replace_region_in_file(
153 "../clippy_lints/src/lib.rs",
154 &format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
157 update_mode == &UpdateMode::Change,
158 || gen_lint_group_list(lints.clone()),
163 if update_mode == &UpdateMode::Check && file_change {
165 "Not all lints defined properly. \
166 Please run `util/dev update_lints` to make sure all lints are defined properly."
168 std::process::exit(1);