1 #![cfg_attr(feature = "deny-warnings", deny(warnings))]
3 use clap::{App, Arg, SubCommand};
7 mod stderr_length_check;
16 let matches = App::new("Clippy developer tooling")
18 SubCommand::with_name("fmt")
19 .about("Run rustfmt on all projects and tests")
21 Arg::with_name("check")
23 .help("Use the rustfmt --check option"),
26 Arg::with_name("verbose")
29 .help("Echo commands run"),
33 SubCommand::with_name("update_lints")
34 .about("Updates lint registration and information from the source code")
37 * the lint count in README.md is correct\n \
38 * the changelog contains markdown link references at the bottom\n \
39 * all lint groups include the correct lints\n \
40 * lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
41 * all lints are registered in the lint store",
43 .arg(Arg::with_name("print-only").long("print-only").help(
44 "Print a table of lints to STDOUT. \
45 This does not include deprecated and internal lints. \
46 (Does not modify any files)",
49 Arg::with_name("check")
51 .help("Checks that util/dev update_lints has been run. Used on CI."),
55 Arg::with_name("limit-stderr-length")
56 .long("limit-stderr-length")
57 .help("Ensures that stderr files do not grow longer than a certain amount of lines."),
61 if matches.is_present("limit-stderr-length") {
62 stderr_length_check::check();
65 match matches.subcommand() {
66 ("fmt", Some(matches)) => {
67 fmt::run(matches.is_present("check"), matches.is_present("verbose"));
69 ("update_lints", Some(matches)) => {
70 if matches.is_present("print-only") {
72 } else if matches.is_present("check") {
73 update_lints(&UpdateMode::Check);
75 update_lints(&UpdateMode::Change);
83 let lint_list = gather_all();
84 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
85 let lint_count = usable_lints.len();
86 let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
88 for (lint_group, mut lints) in grouped_by_lint_group {
89 if lint_group == "Deprecated" {
92 println!("\n## {}", lint_group);
94 lints.sort_by_key(|l| l.name.clone());
100 clippy_dev::DOCS_LINK.clone(),
107 println!("there are {} lints", lint_count);
110 #[allow(clippy::too_many_lines)]
111 fn update_lints(update_mode: &UpdateMode) {
112 let lint_list: Vec<Lint> = gather_all().collect();
114 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
115 let lint_count = usable_lints.len();
117 let mut sorted_usable_lints = usable_lints.clone();
118 sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
120 let mut file_change = replace_region_in_file(
121 "../src/lintlist/mod.rs",
125 update_mode == &UpdateMode::Change,
128 "pub const ALL_LINTS: [Lint; {}] = {:#?};",
129 sorted_usable_lints.len(),
133 .map(ToString::to_string)
139 file_change |= replace_region_in_file(
141 r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
144 update_mode == &UpdateMode::Change,
147 format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
152 file_change |= replace_region_in_file(
154 "<!-- begin autogenerated links to lint list -->",
155 "<!-- end autogenerated links to lint list -->",
157 update_mode == &UpdateMode::Change,
158 || gen_changelog_lint_list(lint_list.clone()),
162 file_change |= replace_region_in_file(
163 "../clippy_lints/src/lib.rs",
164 "begin deprecated lints",
165 "end deprecated lints",
167 update_mode == &UpdateMode::Change,
168 || gen_deprecated(&lint_list),
172 file_change |= replace_region_in_file(
173 "../clippy_lints/src/lib.rs",
174 "begin register lints",
175 "end register lints",
177 update_mode == &UpdateMode::Change,
178 || gen_register_lint_list(&lint_list),
182 file_change |= replace_region_in_file(
183 "../clippy_lints/src/lib.rs",
184 "begin lints modules",
187 update_mode == &UpdateMode::Change,
188 || gen_modules_list(lint_list.clone()),
192 // Generate lists of lints in the clippy::all lint group
193 file_change |= replace_region_in_file(
194 "../clippy_lints/src/lib.rs",
195 r#"store.register_group\(true, "clippy::all""#,
198 update_mode == &UpdateMode::Change,
200 // clippy::all should only include the following lint groups:
201 let all_group_lints = usable_lints
205 l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
209 gen_lint_group_list(all_group_lints)
214 // Generate the list of lints for all other lint groups
215 for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
216 file_change |= replace_region_in_file(
217 "../clippy_lints/src/lib.rs",
218 &format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
221 update_mode == &UpdateMode::Change,
222 || gen_lint_group_list(lints.clone()),
227 if update_mode == &UpdateMode::Check && file_change {
229 "Not all lints defined properly. \
230 Please run `util/dev update_lints` to make sure all lints are defined properly."
232 std::process::exit(1);