2 gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
3 replace_region_in_file, Lint, DOCS_LINK,
7 #[derive(Clone, Copy, PartialEq)]
13 #[allow(clippy::too_many_lines)]
14 pub fn run(update_mode: UpdateMode) {
15 let lint_list: Vec<Lint> = gather_all().collect();
17 let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
19 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
20 let usable_lint_count = usable_lints.len();
22 let mut sorted_usable_lints = usable_lints.clone();
23 sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
25 let mut file_change = replace_region_in_file(
26 Path::new("src/lintlist/mod.rs"),
30 update_mode == UpdateMode::Change,
33 "pub const ALL_LINTS: [Lint; {}] = {:#?};",
34 sorted_usable_lints.len(),
38 .map(ToString::to_string)
44 file_change |= replace_region_in_file(
45 Path::new("README.md"),
46 &format!(r#"\[There are \d+ lints included in this crate!\]\({}\)"#, DOCS_LINK),
49 update_mode == UpdateMode::Change,
52 "[There are {} lints included in this crate!]({})",
53 usable_lint_count, DOCS_LINK
59 file_change |= replace_region_in_file(
60 Path::new("CHANGELOG.md"),
61 "<!-- begin autogenerated links to lint list -->",
62 "<!-- end autogenerated links to lint list -->",
64 update_mode == UpdateMode::Change,
65 || gen_changelog_lint_list(lint_list.clone()),
69 file_change |= replace_region_in_file(
70 Path::new("clippy_lints/src/lib.rs"),
71 "begin deprecated lints",
72 "end deprecated lints",
74 update_mode == UpdateMode::Change,
75 || gen_deprecated(&lint_list),
79 file_change |= replace_region_in_file(
80 Path::new("clippy_lints/src/lib.rs"),
81 "begin register lints",
84 update_mode == UpdateMode::Change,
85 || gen_register_lint_list(&lint_list),
89 file_change |= replace_region_in_file(
90 Path::new("clippy_lints/src/lib.rs"),
91 "begin lints modules",
94 update_mode == UpdateMode::Change,
95 || gen_modules_list(lint_list.clone()),
99 // Generate lists of lints in the clippy::all lint group
100 file_change |= replace_region_in_file(
101 Path::new("clippy_lints/src/lib.rs"),
102 r#"store.register_group\(true, "clippy::all""#,
105 update_mode == UpdateMode::Change,
107 // clippy::all should only include the following lint groups:
108 let all_group_lints = usable_lints
112 l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
116 gen_lint_group_list(all_group_lints)
121 // Generate the list of lints for all other lint groups
122 for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
123 file_change |= replace_region_in_file(
124 Path::new("clippy_lints/src/lib.rs"),
125 &format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
128 update_mode == UpdateMode::Change,
129 || gen_lint_group_list(lints.clone()),
134 if update_mode == UpdateMode::Check && file_change {
136 "Not all lints defined properly. \
137 Please run `cargo dev update_lints` to make sure all lints are defined properly."
139 std::process::exit(1);
143 pub fn print_lints() {
144 let lint_list = gather_all();
145 let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
146 let usable_lint_count = usable_lints.len();
147 let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
149 for (lint_group, mut lints) in grouped_by_lint_group {
150 if lint_group == "Deprecated" {
153 println!("\n## {}", lint_group);
155 lints.sort_by_key(|l| l.name.clone());
158 println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
162 println!("there are {} lints", usable_lint_count);