Skip to content

Stop updating the lint counter with every new lint #5398

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/clippy_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion clippy_dev/src/fmt.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
5 changes: 5 additions & 0 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
196 changes: 11 additions & 185 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand Down Expand Up @@ -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)) => {
Expand All @@ -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),
}
},
_ => {},
}
}

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
)]
("limit_stderr_length", _) => {
stderr_length_check::check();
},
)
.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);
_ => {},
}
}
7 changes: 6 additions & 1 deletion clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
4 changes: 1 addition & 3 deletions clippy_dev/src/stderr_length_check.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Loading