2 extern crate clippy_dev;
5 use clap::{App, Arg, SubCommand};
7 mod stderr_length_check;
16 let matches = App::new("Clippy developer tooling")
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."),
40 Arg::with_name("limit-stderr-length")
41 .long("limit-stderr-length")
42 .help("Ensures that stderr files do not grow longer than a certain amount of lines."),
46 if matches.is_present("limit-stderr-length") {
47 stderr_length_check::check();
49 if let Some(matches) = matches.subcommand_matches("update_lints") {
50 if matches.is_present("print-only") {
52 } else if matches.is_present("check") {
53 update_lints(&UpdateMode::Check);
55 update_lints(&UpdateMode::Change);
61 let lint_list = gather_all();
62 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
63 let lint_count = usable_lints.len();
64 let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
66 for (lint_group, mut lints) in grouped_by_lint_group {
67 if lint_group == "Deprecated" {
70 println!("\n## {}", lint_group);
72 lints.sort_by_key(|l| l.name.clone());
78 clippy_dev::DOCS_LINK.clone(),
85 println!("there are {} lints", lint_count);
88 fn update_lints(update_mode: &UpdateMode) {
89 let lint_list: Vec<Lint> = gather_all().collect();
91 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
92 let lint_count = usable_lints.len();
94 let mut sorted_usable_lints = usable_lints.clone();
95 sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
98 "../src/lintlist/mod.rs",
101 //! This file is managed by util/dev update_lints. Do not edit.
106 pub const ALL_LINTS: [Lint; {}] = {:#?};\n",
107 sorted_usable_lints.len(),
111 .expect("can write to file");
113 let mut file_change = replace_region_in_file(
115 r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
118 update_mode == &UpdateMode::Change,
121 format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
126 file_change |= replace_region_in_file(
128 "<!-- begin autogenerated links to lint list -->",
129 "<!-- end autogenerated links to lint list -->",
131 update_mode == &UpdateMode::Change,
132 || gen_changelog_lint_list(lint_list.clone()),
136 file_change |= replace_region_in_file(
137 "../clippy_lints/src/lib.rs",
138 "begin deprecated lints",
139 "end deprecated lints",
141 update_mode == &UpdateMode::Change,
142 || gen_deprecated(&lint_list),
146 file_change |= replace_region_in_file(
147 "../clippy_lints/src/lib.rs",
148 "begin lints modules",
151 update_mode == &UpdateMode::Change,
152 || gen_modules_list(lint_list.clone()),
156 // Generate lists of lints in the clippy::all lint group
157 file_change |= replace_region_in_file(
158 "../clippy_lints/src/lib.rs",
159 r#"reg.register_lint_group\("clippy::all""#,
162 update_mode == &UpdateMode::Change,
164 // clippy::all should only include the following lint groups:
165 let all_group_lints = usable_lints
169 l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
173 gen_lint_group_list(all_group_lints)
178 // Generate the list of lints for all other lint groups
179 for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
180 file_change |= replace_region_in_file(
181 "../clippy_lints/src/lib.rs",
182 &format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
185 update_mode == &UpdateMode::Change,
186 || gen_lint_group_list(lints.clone()),
191 if update_mode == &UpdateMode::Check && file_change {
193 "Not all lints defined properly. \
194 Please run `util/dev update_lints` to make sure all lints are defined properly."
196 std::process::exit(1);