2 extern crate clippy_dev;
5 use clap::{App, Arg, SubCommand};
15 let matches = App::new("Clippy developer tooling")
17 SubCommand::with_name("update_lints")
20 * the lint count in README.md is correct\n \
21 * the changelog contains markdown link references at the bottom\n \
22 * all lint groups include the correct lints\n \
23 * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
24 * all lints are registered in the lint store",
26 .arg(Arg::with_name("print-only").long("print-only").help(
27 "Print a table of lints to STDOUT. \
28 This does not include deprecated and internal lints. \
29 (Does not modify any files)",
32 Arg::with_name("check")
34 .help("Checks that util/dev update_lints has been run. Used on CI."),
39 if let Some(matches) = matches.subcommand_matches("update_lints") {
40 if matches.is_present("print-only") {
42 } else if matches.is_present("check") {
43 update_lints(&UpdateMode::Check);
45 update_lints(&UpdateMode::Change);
51 let lint_list = gather_all();
52 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
53 let lint_count = usable_lints.len();
54 let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
56 for (lint_group, mut lints) in grouped_by_lint_group {
57 if lint_group == "Deprecated" {
60 println!("\n## {}", lint_group);
62 lints.sort_by_key(|l| l.name.clone());
68 clippy_dev::DOCS_LINK.clone(),
75 println!("there are {} lints", lint_count);
78 fn update_lints(update_mode: &UpdateMode) {
79 let lint_list: Vec<Lint> = gather_all().collect();
80 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
81 let lint_count = usable_lints.len();
83 let mut file_change = replace_region_in_file(
85 r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
88 update_mode == &UpdateMode::Change,
91 format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
96 file_change |= replace_region_in_file(
98 "<!-- begin autogenerated links to lint list -->",
99 "<!-- end autogenerated links to lint list -->",
101 update_mode == &UpdateMode::Change,
102 || gen_changelog_lint_list(lint_list.clone()),
106 file_change |= replace_region_in_file(
107 "../clippy_lints/src/lib.rs",
108 "begin deprecated lints",
109 "end deprecated lints",
111 update_mode == &UpdateMode::Change,
112 || gen_deprecated(&lint_list),
116 file_change |= replace_region_in_file(
117 "../clippy_lints/src/lib.rs",
118 "begin lints modules",
121 update_mode == &UpdateMode::Change,
122 || gen_modules_list(lint_list.clone()),
126 // Generate lists of lints in the clippy::all lint group
127 file_change |= replace_region_in_file(
128 "../clippy_lints/src/lib.rs",
129 r#"reg.register_lint_group\("clippy::all""#,
132 update_mode == &UpdateMode::Change,
134 // clippy::all should only include the following lint groups:
135 let all_group_lints = usable_lints
139 l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
143 gen_lint_group_list(all_group_lints)
148 // Generate the list of lints for all other lint groups
149 for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
150 file_change |= replace_region_in_file(
151 "../clippy_lints/src/lib.rs",
152 &format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
155 update_mode == &UpdateMode::Change,
156 || gen_lint_group_list(lints.clone()),
161 if update_mode == &UpdateMode::Check && file_change {
163 "Not all lints defined properly. \
164 Please run `util/dev update_lints` to make sure all lints are defined properly."
166 std::process::exit(1);