Auto merge of #5398 - flip1995:deescalate, r=Manishearth
Stop updating the lint counter with every new lint r? @Manishearth This PR does two things: 1. Clean up the clippy_dev module a bit (first 3 commits; cc #5394 ) 2. Make the counter in the README count in steps of 50 lints. Also use a `lazy_static` `Vec` for the lint list, so no counter is required there anymore. changelog: none
This commit is contained in:
commit
c211cea3e9
4
.github/workflows/clippy_dev.yml
vendored
4
.github/workflows/clippy_dev.yml
vendored
@ -38,8 +38,8 @@ jobs:
|
||||
run: cargo build --features deny-warnings
|
||||
working-directory: clippy_dev
|
||||
|
||||
- name: Test limit-stderr-length
|
||||
run: cargo dev --limit-stderr-length
|
||||
- name: Test limit_stderr_length
|
||||
run: cargo dev limit_stderr_length
|
||||
|
||||
- name: Test update_lints
|
||||
run: cargo dev update_lints --check
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
|
||||
|
||||
[There are 363 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
|
||||
[There are over 350 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
|
||||
|
||||
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use clippy_dev::clippy_project_root;
|
||||
use crate::clippy_project_root;
|
||||
use shell_escape::escape;
|
||||
use std::ffi::OsStr;
|
||||
use std::io;
|
||||
|
@ -9,6 +9,11 @@ use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use walkdir::WalkDir;
|
||||
|
||||
pub mod fmt;
|
||||
pub mod new_lint;
|
||||
pub mod stderr_length_check;
|
||||
pub mod update_lints;
|
||||
|
||||
lazy_static! {
|
||||
static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
|
||||
r#"(?x)
|
||||
|
@ -1,21 +1,7 @@
|
||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||
|
||||
use clap::{App, Arg, SubCommand};
|
||||
use clippy_dev::{
|
||||
gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
|
||||
replace_region_in_file, Lint, DOCS_LINK,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
mod fmt;
|
||||
mod new_lint;
|
||||
mod stderr_length_check;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
enum UpdateMode {
|
||||
Check,
|
||||
Change,
|
||||
}
|
||||
use clippy_dev::{fmt, new_lint, stderr_length_check, update_lints};
|
||||
|
||||
fn main() {
|
||||
let matches = App::new("Clippy developer tooling")
|
||||
@ -97,28 +83,23 @@ fn main() {
|
||||
.takes_value(true),
|
||||
),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("limit-stderr-length")
|
||||
.long("limit-stderr-length")
|
||||
.help("Ensures that stderr files do not grow longer than a certain amount of lines."),
|
||||
.subcommand(
|
||||
SubCommand::with_name("limit_stderr_length")
|
||||
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if matches.is_present("limit-stderr-length") {
|
||||
stderr_length_check::check();
|
||||
}
|
||||
|
||||
match matches.subcommand() {
|
||||
("fmt", Some(matches)) => {
|
||||
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
|
||||
},
|
||||
("update_lints", Some(matches)) => {
|
||||
if matches.is_present("print-only") {
|
||||
print_lints();
|
||||
update_lints::print_lints();
|
||||
} else if matches.is_present("check") {
|
||||
update_lints(UpdateMode::Check);
|
||||
update_lints::run(update_lints::UpdateMode::Check);
|
||||
} else {
|
||||
update_lints(UpdateMode::Change);
|
||||
update_lints::run(update_lints::UpdateMode::Change);
|
||||
}
|
||||
},
|
||||
("new_lint", Some(matches)) => {
|
||||
@ -127,168 +108,13 @@ fn main() {
|
||||
matches.value_of("name"),
|
||||
matches.value_of("category"),
|
||||
) {
|
||||
Ok(_) => update_lints(UpdateMode::Change),
|
||||
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
|
||||
Err(e) => eprintln!("Unable to create lint: {}", e),
|
||||
}
|
||||
},
|
||||
("limit_stderr_length", _) => {
|
||||
stderr_length_check::check();
|
||||
},
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
fn print_lints() {
|
||||
let lint_list = gather_all();
|
||||
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
|
||||
let usable_lint_count = usable_lints.len();
|
||||
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
|
||||
|
||||
for (lint_group, mut lints) in grouped_by_lint_group {
|
||||
if lint_group == "Deprecated" {
|
||||
continue;
|
||||
}
|
||||
println!("\n## {}", lint_group);
|
||||
|
||||
lints.sort_by_key(|l| l.name.clone());
|
||||
|
||||
for lint in lints {
|
||||
println!(
|
||||
"* [{}]({}#{}) ({})",
|
||||
lint.name,
|
||||
clippy_dev::DOCS_LINK,
|
||||
lint.name,
|
||||
lint.desc
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
println!("there are {} lints", usable_lint_count);
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn update_lints(update_mode: UpdateMode) {
|
||||
let lint_list: Vec<Lint> = gather_all().collect();
|
||||
|
||||
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
|
||||
|
||||
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
|
||||
let usable_lint_count = usable_lints.len();
|
||||
|
||||
let mut sorted_usable_lints = usable_lints.clone();
|
||||
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
|
||||
|
||||
let mut file_change = replace_region_in_file(
|
||||
Path::new("src/lintlist/mod.rs"),
|
||||
"begin lint list",
|
||||
"end lint list",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
format!(
|
||||
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
|
||||
sorted_usable_lints.len(),
|
||||
sorted_usable_lints
|
||||
)
|
||||
.lines()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("README.md"),
|
||||
&format!(r#"\[There are \d+ lints included in this crate!\]\({}\)"#, DOCS_LINK),
|
||||
"",
|
||||
true,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
vec![format!(
|
||||
"[There are {} lints included in this crate!]({})",
|
||||
usable_lint_count, DOCS_LINK
|
||||
)]
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("CHANGELOG.md"),
|
||||
"<!-- begin autogenerated links to lint list -->",
|
||||
"<!-- end autogenerated links to lint list -->",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_changelog_lint_list(lint_list.clone()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin deprecated lints",
|
||||
"end deprecated lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_deprecated(&lint_list),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin register lints",
|
||||
"end register lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_register_lint_list(&lint_list),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin lints modules",
|
||||
"end lints modules",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_modules_list(lint_list.clone()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
// Generate lists of lints in the clippy::all lint group
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
r#"store.register_group\(true, "clippy::all""#,
|
||||
r#"\]\);"#,
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
// 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)
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
// Generate the list of lints for all other lint groups
|
||||
for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
|
||||
r#"\]\);"#,
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_lint_group_list(lints.clone()),
|
||||
)
|
||||
.changed;
|
||||
}
|
||||
|
||||
if update_mode == UpdateMode::Check && file_change {
|
||||
println!(
|
||||
"Not all lints defined properly. \
|
||||
Please run `cargo dev update_lints` to make sure all lints are defined properly."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,15 @@
|
||||
use clippy_dev::clippy_project_root;
|
||||
use crate::clippy_project_root;
|
||||
use std::fs::{File, OpenOptions};
|
||||
use std::io;
|
||||
use std::io::prelude::*;
|
||||
use std::io::ErrorKind;
|
||||
use std::path::Path;
|
||||
|
||||
/// Creates files required to implement and test a new lint and runs `update_lints`.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// This function errors, if the files couldn't be created
|
||||
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
|
||||
let pass = pass.expect("`pass` argument is validated by clap");
|
||||
let lint_name = lint_name.expect("`name` argument is validated by clap");
|
||||
|
@ -1,11 +1,9 @@
|
||||
use crate::clippy_project_root;
|
||||
use std::ffi::OsStr;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use clippy_dev::clippy_project_root;
|
||||
|
||||
// The maximum length allowed for stderr files.
|
||||
//
|
||||
// We limit this because small files are easier to deal with than bigger files.
|
||||
|
166
clippy_dev/src/update_lints.rs
Normal file
166
clippy_dev/src/update_lints.rs
Normal file
@ -0,0 +1,166 @@
|
||||
use crate::{
|
||||
gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
|
||||
replace_region_in_file, Lint, DOCS_LINK,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq)]
|
||||
pub enum UpdateMode {
|
||||
Check,
|
||||
Change,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
pub fn run(update_mode: UpdateMode) {
|
||||
let lint_list: Vec<Lint> = gather_all().collect();
|
||||
|
||||
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
|
||||
|
||||
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
|
||||
let usable_lint_count = round_to_fifty(usable_lints.len());
|
||||
|
||||
let mut sorted_usable_lints = usable_lints.clone();
|
||||
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
|
||||
|
||||
let mut file_change = replace_region_in_file(
|
||||
Path::new("src/lintlist/mod.rs"),
|
||||
"begin lint list",
|
||||
"end lint list",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
format!("pub static ref ALL_LINTS: Vec<Lint> = vec!{:#?};", sorted_usable_lints)
|
||||
.lines()
|
||||
.map(ToString::to_string)
|
||||
.collect::<Vec<_>>()
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("README.md"),
|
||||
&format!(
|
||||
r#"\[There are over \d+ lints included in this crate!\]\({}\)"#,
|
||||
DOCS_LINK
|
||||
),
|
||||
"",
|
||||
true,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
vec![format!(
|
||||
"[There are over {} lints included in this crate!]({})",
|
||||
usable_lint_count, DOCS_LINK
|
||||
)]
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("CHANGELOG.md"),
|
||||
"<!-- begin autogenerated links to lint list -->",
|
||||
"<!-- end autogenerated links to lint list -->",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_changelog_lint_list(lint_list.clone()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin deprecated lints",
|
||||
"end deprecated lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_deprecated(&lint_list),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin register lints",
|
||||
"end register lints",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_register_lint_list(&lint_list),
|
||||
)
|
||||
.changed;
|
||||
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
"begin lints modules",
|
||||
"end lints modules",
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_modules_list(lint_list.clone()),
|
||||
)
|
||||
.changed;
|
||||
|
||||
// Generate lists of lints in the clippy::all lint group
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
r#"store.register_group\(true, "clippy::all""#,
|
||||
r#"\]\);"#,
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| {
|
||||
// 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)
|
||||
},
|
||||
)
|
||||
.changed;
|
||||
|
||||
// Generate the list of lints for all other lint groups
|
||||
for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
|
||||
file_change |= replace_region_in_file(
|
||||
Path::new("clippy_lints/src/lib.rs"),
|
||||
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
|
||||
r#"\]\);"#,
|
||||
false,
|
||||
update_mode == UpdateMode::Change,
|
||||
|| gen_lint_group_list(lints.clone()),
|
||||
)
|
||||
.changed;
|
||||
}
|
||||
|
||||
if update_mode == UpdateMode::Check && file_change {
|
||||
println!(
|
||||
"Not all lints defined properly. \
|
||||
Please run `cargo dev update_lints` to make sure all lints are defined properly."
|
||||
);
|
||||
std::process::exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn print_lints() {
|
||||
let lint_list = gather_all();
|
||||
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
|
||||
let usable_lint_count = usable_lints.len();
|
||||
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
|
||||
|
||||
for (lint_group, mut lints) in grouped_by_lint_group {
|
||||
if lint_group == "Deprecated" {
|
||||
continue;
|
||||
}
|
||||
println!("\n## {}", lint_group);
|
||||
|
||||
lints.sort_by_key(|l| l.name.clone());
|
||||
|
||||
for lint in lints {
|
||||
println!("* [{}]({}#{}) ({})", lint.name, DOCS_LINK, lint.name, lint.desc);
|
||||
}
|
||||
}
|
||||
|
||||
println!("there are {} lints", usable_lint_count);
|
||||
}
|
||||
|
||||
fn round_to_fifty(count: usize) -> usize {
|
||||
count / 50 * 50
|
||||
}
|
@ -1,12 +1,15 @@
|
||||
//! This file is managed by `cargo dev update_lints`. Do not edit.
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
pub mod lint;
|
||||
pub use lint::Level;
|
||||
pub use lint::Lint;
|
||||
pub use lint::LINT_LEVELS;
|
||||
|
||||
lazy_static! {
|
||||
// begin lint list, do not remove this comment, it’s used in `update_lints`
|
||||
pub const ALL_LINTS: [Lint; 363] = [
|
||||
pub static ref ALL_LINTS: Vec<Lint> = vec![
|
||||
Lint {
|
||||
name: "absurd_extreme_comparisons",
|
||||
group: "correctness",
|
||||
@ -2550,3 +2553,4 @@ pub const ALL_LINTS: [Lint; 363] = [
|
||||
},
|
||||
];
|
||||
// end lint list, do not remove this comment, it’s used in `update_lints`
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user