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);
18 let deprecated_lints = Lint::deprecated_lints(&lint_list);
19 let usable_lints = Lint::usable_lints(&lint_list);
20 let mut sorted_usable_lints = usable_lints.clone();
21 sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
23 let usable_lint_count = round_to_fifty(usable_lints.len());
25 let mut file_change = false;
27 file_change |= replace_region_in_file(
28 Path::new("README.md"),
30 r#"\[There are over \d+ lints included in this crate!\]\({}\)"#,
35 update_mode == UpdateMode::Change,
38 "[There are over {} lints included in this crate!]({})",
39 usable_lint_count, DOCS_LINK
45 file_change |= replace_region_in_file(
46 Path::new("CHANGELOG.md"),
47 "<!-- begin autogenerated links to lint list -->",
48 "<!-- end autogenerated links to lint list -->",
50 update_mode == UpdateMode::Change,
51 || gen_changelog_lint_list(usable_lints.iter().chain(deprecated_lints.iter())),
55 file_change |= replace_region_in_file(
56 Path::new("clippy_lints/src/lib.rs"),
57 "begin deprecated lints",
58 "end deprecated lints",
60 update_mode == UpdateMode::Change,
61 || gen_deprecated(deprecated_lints.iter()),
65 file_change |= replace_region_in_file(
66 Path::new("clippy_lints/src/lib.rs"),
67 "begin register lints",
70 update_mode == UpdateMode::Change,
71 || gen_register_lint_list(internal_lints.iter(), usable_lints.iter()),
75 file_change |= replace_region_in_file(
76 Path::new("clippy_lints/src/lib.rs"),
77 "begin lints modules",
80 update_mode == UpdateMode::Change,
81 || gen_modules_list(usable_lints.iter()),
85 // Generate lists of lints in the clippy::all lint group
86 file_change |= replace_region_in_file(
87 Path::new("clippy_lints/src/lib.rs"),
88 r#"store.register_group\(true, "clippy::all""#,
91 update_mode == UpdateMode::Change,
93 // clippy::all should only include the following lint groups:
94 let all_group_lints = usable_lints.iter().filter(|l| {
97 "correctness" | "suspicious" | "style" | "complexity" | "perf"
101 gen_lint_group_list(all_group_lints)
106 // Generate the list of lints for all other lint groups
107 for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
108 file_change |= replace_region_in_file(
109 Path::new("clippy_lints/src/lib.rs"),
110 &format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
113 update_mode == UpdateMode::Change,
114 || gen_lint_group_list(lints.iter()),
119 if update_mode == UpdateMode::Check && file_change {
121 "Not all lints defined properly. \
122 Please run `cargo dev update_lints` to make sure all lints are defined properly."
124 std::process::exit(1);
128 pub fn print_lints() {
129 let lint_list: Vec<Lint> = gather_all().collect();
130 let usable_lints = Lint::usable_lints(&lint_list);
131 let usable_lint_count = usable_lints.len();
132 let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
134 for (lint_group, mut lints) in grouped_by_lint_group {
135 if lint_group == "Deprecated" {
138 println!("\n## {}", lint_group);
140 lints.sort_by_key(|l| l.name.clone());
143 println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
147 println!("there are {} lints", usable_lint_count);
150 fn round_to_fifty(count: usize) -> usize {