2018-10-06 11:18:06 -05:00
|
|
|
// Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
|
2018-07-17 15:50:17 -05:00
|
|
|
extern crate clap;
|
|
|
|
extern crate clippy_dev;
|
|
|
|
extern crate regex;
|
|
|
|
|
|
|
|
use clap::{App, Arg, SubCommand};
|
|
|
|
use clippy_dev::*;
|
|
|
|
|
2018-11-04 02:41:28 -06:00
|
|
|
#[derive(PartialEq)]
|
|
|
|
enum UpdateMode {
|
|
|
|
Check,
|
|
|
|
Change
|
|
|
|
}
|
|
|
|
|
2018-07-17 15:50:17 -05:00
|
|
|
fn main() {
|
|
|
|
let matches = App::new("Clippy developer tooling")
|
|
|
|
.subcommand(
|
|
|
|
SubCommand::with_name("update_lints")
|
2018-11-03 06:59:40 -05:00
|
|
|
.about("Makes sure that:\n \
|
|
|
|
* the lint count in README.md is correct\n \
|
|
|
|
* the changelog contains markdown link references at the bottom\n \
|
2018-11-03 12:48:39 -05:00
|
|
|
* all lint groups include the correct lints\n \
|
2018-11-03 06:59:40 -05:00
|
|
|
* lint modules in `clippy_lints/*` are visible in `src/lib.rs` via `pub mod`\n \
|
|
|
|
* all lints are registered in the lint store")
|
2018-07-17 15:50:17 -05:00
|
|
|
.arg(
|
|
|
|
Arg::with_name("print-only")
|
|
|
|
.long("print-only")
|
2018-11-04 02:41:28 -06:00
|
|
|
.help("Print a table of lints to STDOUT. This does not include deprecated and internal lints. (Does not modify any files)")
|
|
|
|
)
|
|
|
|
.arg(
|
|
|
|
Arg::with_name("check")
|
|
|
|
.long("check")
|
|
|
|
.help("Checks that util/dev update_lints has been run. Used on CI."),
|
2018-07-17 15:50:17 -05:00
|
|
|
)
|
2018-11-04 02:41:28 -06:00
|
|
|
)
|
|
|
|
.get_matches();
|
2018-07-17 15:50:17 -05:00
|
|
|
|
|
|
|
if let Some(matches) = matches.subcommand_matches("update_lints") {
|
|
|
|
if matches.is_present("print-only") {
|
|
|
|
print_lints();
|
2018-11-04 02:41:28 -06:00
|
|
|
} else if matches.is_present("check") {
|
2018-11-05 00:11:25 -06:00
|
|
|
update_lints(&UpdateMode::Check);
|
2018-10-16 01:00:31 -05:00
|
|
|
} else {
|
2018-11-05 00:11:25 -06:00
|
|
|
update_lints(&UpdateMode::Change);
|
2018-07-17 15:50:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn print_lints() {
|
2018-10-16 00:24:32 -05:00
|
|
|
let lint_list = gather_all();
|
|
|
|
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
|
|
|
|
let lint_count = usable_lints.len();
|
|
|
|
let grouped_by_lint_group = Lint::by_lint_group(&usable_lints);
|
2018-09-02 02:45:13 -05:00
|
|
|
|
|
|
|
for (lint_group, mut lints) in grouped_by_lint_group {
|
|
|
|
if lint_group == "Deprecated" { continue; }
|
|
|
|
println!("\n## {}", lint_group);
|
|
|
|
|
2018-10-15 14:02:38 -05:00
|
|
|
lints.sort_by_key(|l| l.name.clone());
|
2018-09-02 02:45:13 -05:00
|
|
|
|
|
|
|
for lint in lints {
|
2018-07-17 15:50:17 -05:00
|
|
|
println!("* [{}]({}#{}) ({})", lint.name, clippy_dev::DOCS_LINK.clone(), lint.name, lint.desc);
|
|
|
|
}
|
|
|
|
}
|
2018-09-02 02:45:13 -05:00
|
|
|
|
2018-10-16 00:24:32 -05:00
|
|
|
println!("there are {} lints", lint_count);
|
2018-07-17 15:50:17 -05:00
|
|
|
}
|
2018-10-16 01:00:31 -05:00
|
|
|
|
2018-11-05 00:11:25 -06:00
|
|
|
fn update_lints(update_mode: &UpdateMode) {
|
2018-10-17 01:18:05 -05:00
|
|
|
let lint_list: Vec<Lint> = gather_all().collect();
|
|
|
|
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
|
2018-10-16 01:00:31 -05:00
|
|
|
let lint_count = usable_lints.len();
|
|
|
|
|
2018-11-04 02:41:28 -06:00
|
|
|
let mut file_change = replace_region_in_file(
|
2018-10-16 01:00:31 -05:00
|
|
|
"../README.md",
|
2018-11-21 21:40:09 -06:00
|
|
|
r#"\[There are \d+ lints included in this crate!\]\(https://rust-lang.github.io/rust-clippy/master/index.html\)"#,
|
2018-10-16 01:00:31 -05:00
|
|
|
"",
|
|
|
|
true,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-10-16 01:00:31 -05:00
|
|
|
|| {
|
|
|
|
vec![
|
2018-11-21 21:40:09 -06:00
|
|
|
format!("[There are {} lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)", lint_count)
|
2018-10-16 01:00:31 -05:00
|
|
|
]
|
|
|
|
}
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
2018-10-17 01:18:05 -05:00
|
|
|
|
2018-11-04 02:41:28 -06:00
|
|
|
file_change |= replace_region_in_file(
|
2018-10-17 01:18:05 -05:00
|
|
|
"../CHANGELOG.md",
|
|
|
|
"<!-- begin autogenerated links to lint list -->",
|
|
|
|
"<!-- end autogenerated links to lint list -->",
|
|
|
|
false,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-10-17 01:18:05 -05:00
|
|
|
|| { gen_changelog_lint_list(lint_list.clone()) }
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
2018-10-31 02:03:50 -05:00
|
|
|
|
2018-11-04 02:41:28 -06:00
|
|
|
file_change |= replace_region_in_file(
|
2018-10-31 02:03:50 -05:00
|
|
|
"../clippy_lints/src/lib.rs",
|
|
|
|
"begin deprecated lints",
|
|
|
|
"end deprecated lints",
|
|
|
|
false,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-10-31 15:54:30 -05:00
|
|
|
|| { gen_deprecated(&lint_list) }
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
2018-11-01 14:16:38 -05:00
|
|
|
|
2018-11-04 02:41:28 -06:00
|
|
|
file_change |= replace_region_in_file(
|
2018-11-01 14:16:38 -05:00
|
|
|
"../clippy_lints/src/lib.rs",
|
|
|
|
"begin lints modules",
|
|
|
|
"end lints modules",
|
|
|
|
false,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-11-01 14:16:38 -05:00
|
|
|
|| { gen_modules_list(lint_list.clone()) }
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
2018-11-03 06:59:13 -05:00
|
|
|
|
|
|
|
// Generate lists of lints in the clippy::all lint group
|
2018-11-04 02:41:28 -06:00
|
|
|
file_change |= replace_region_in_file(
|
2018-11-03 06:59:13 -05:00
|
|
|
"../clippy_lints/src/lib.rs",
|
|
|
|
r#"reg.register_lint_group\("clippy::all""#,
|
|
|
|
r#"\]\);"#,
|
|
|
|
false,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-11-03 06:59:13 -05:00
|
|
|
|| {
|
|
|
|
// clippy::all should only include the following lint groups:
|
|
|
|
let all_group_lints = usable_lints.clone().into_iter().filter(|l| {
|
|
|
|
l.group == "correctness" ||
|
|
|
|
l.group == "style" ||
|
|
|
|
l.group == "complexity" ||
|
|
|
|
l.group == "perf"
|
|
|
|
}).collect();
|
|
|
|
|
|
|
|
gen_lint_group_list(all_group_lints)
|
|
|
|
}
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
2018-11-03 06:59:13 -05:00
|
|
|
|
|
|
|
// Generate the list of lints for all other lint groups
|
|
|
|
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
|
2018-11-04 02:41:28 -06:00
|
|
|
file_change |= replace_region_in_file(
|
2018-11-03 06:59:13 -05:00
|
|
|
"../clippy_lints/src/lib.rs",
|
|
|
|
&format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
|
|
|
|
r#"\]\);"#,
|
|
|
|
false,
|
2018-11-05 00:11:25 -06:00
|
|
|
update_mode == &UpdateMode::Change,
|
2018-11-03 06:59:13 -05:00
|
|
|
|| { gen_lint_group_list(lints.clone()) }
|
2018-11-04 02:41:28 -06:00
|
|
|
).changed;
|
|
|
|
}
|
|
|
|
|
2018-11-05 00:11:25 -06:00
|
|
|
if update_mode == &UpdateMode::Check && file_change {
|
2018-11-04 15:08:18 -06:00
|
|
|
println!("Not all lints defined properly. Please run `util/dev update_lints` to make sure all lints are defined properly.");
|
2018-11-04 02:41:28 -06:00
|
|
|
std::process::exit(1);
|
2018-11-03 06:59:13 -05:00
|
|
|
}
|
2018-10-16 01:00:31 -05:00
|
|
|
}
|