Skip to content

Commit c211cea

Browse files
committed
Auto merge of rust-lang#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 rust-lang#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
2 parents 09fe163 + cbdf4cc commit c211cea

File tree

9 files changed

+198
-194
lines changed

9 files changed

+198
-194
lines changed

.github/workflows/clippy_dev.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ jobs:
3838
run: cargo build --features deny-warnings
3939
working-directory: clippy_dev
4040

41-
- name: Test limit-stderr-length
42-
run: cargo dev --limit-stderr-length
41+
- name: Test limit_stderr_length
42+
run: cargo dev limit_stderr_length
4343

4444
- name: Test update_lints
4545
run: cargo dev update_lints --check

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
A collection of lints to catch common mistakes and improve your [Rust](https://github.com/rust-lang/rust) code.
77

8-
[There are 363 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are over 350 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

1010
We have a bunch of lint categories to allow you to choose how much Clippy is supposed to ~~annoy~~ help you:
1111

clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clippy_dev::clippy_project_root;
1+
use crate::clippy_project_root;
22
use shell_escape::escape;
33
use std::ffi::OsStr;
44
use std::io;

clippy_dev/src/lib.rs

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ use std::fs;
99
use std::path::{Path, PathBuf};
1010
use walkdir::WalkDir;
1111

12+
pub mod fmt;
13+
pub mod new_lint;
14+
pub mod stderr_length_check;
15+
pub mod update_lints;
16+
1217
lazy_static! {
1318
static ref DEC_CLIPPY_LINT_RE: Regex = Regex::new(
1419
r#"(?x)

clippy_dev/src/main.rs

+11-185
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

33
use clap::{App, Arg, SubCommand};
4-
use clippy_dev::{
5-
gather_all, gen_changelog_lint_list, gen_deprecated, gen_lint_group_list, gen_modules_list, gen_register_lint_list,
6-
replace_region_in_file, Lint, DOCS_LINK,
7-
};
8-
use std::path::Path;
9-
10-
mod fmt;
11-
mod new_lint;
12-
mod stderr_length_check;
13-
14-
#[derive(Clone, Copy, PartialEq)]
15-
enum UpdateMode {
16-
Check,
17-
Change,
18-
}
4+
use clippy_dev::{fmt, new_lint, stderr_length_check, update_lints};
195

206
fn main() {
217
let matches = App::new("Clippy developer tooling")
@@ -97,28 +83,23 @@ fn main() {
9783
.takes_value(true),
9884
),
9985
)
100-
.arg(
101-
Arg::with_name("limit-stderr-length")
102-
.long("limit-stderr-length")
103-
.help("Ensures that stderr files do not grow longer than a certain amount of lines."),
86+
.subcommand(
87+
SubCommand::with_name("limit_stderr_length")
88+
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
10489
)
10590
.get_matches();
10691

107-
if matches.is_present("limit-stderr-length") {
108-
stderr_length_check::check();
109-
}
110-
11192
match matches.subcommand() {
11293
("fmt", Some(matches)) => {
11394
fmt::run(matches.is_present("check"), matches.is_present("verbose"));
11495
},
11596
("update_lints", Some(matches)) => {
11697
if matches.is_present("print-only") {
117-
print_lints();
98+
update_lints::print_lints();
11899
} else if matches.is_present("check") {
119-
update_lints(UpdateMode::Check);
100+
update_lints::run(update_lints::UpdateMode::Check);
120101
} else {
121-
update_lints(UpdateMode::Change);
102+
update_lints::run(update_lints::UpdateMode::Change);
122103
}
123104
},
124105
("new_lint", Some(matches)) => {
@@ -127,168 +108,13 @@ fn main() {
127108
matches.value_of("name"),
128109
matches.value_of("category"),
129110
) {
130-
Ok(_) => update_lints(UpdateMode::Change),
111+
Ok(_) => update_lints::run(update_lints::UpdateMode::Change),
131112
Err(e) => eprintln!("Unable to create lint: {}", e),
132113
}
133114
},
134-
_ => {},
135-
}
136-
}
137-
138-
fn print_lints() {
139-
let lint_list = gather_all();
140-
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list).collect();
141-
let usable_lint_count = usable_lints.len();
142-
let grouped_by_lint_group = Lint::by_lint_group(usable_lints.into_iter());
143-
144-
for (lint_group, mut lints) in grouped_by_lint_group {
145-
if lint_group == "Deprecated" {
146-
continue;
147-
}
148-
println!("\n## {}", lint_group);
149-
150-
lints.sort_by_key(|l| l.name.clone());
151-
152-
for lint in lints {
153-
println!(
154-
"* [{}]({}#{}) ({})",
155-
lint.name,
156-
clippy_dev::DOCS_LINK,
157-
lint.name,
158-
lint.desc
159-
);
160-
}
161-
}
162-
163-
println!("there are {} lints", usable_lint_count);
164-
}
165-
166-
#[allow(clippy::too_many_lines)]
167-
fn update_lints(update_mode: UpdateMode) {
168-
let lint_list: Vec<Lint> = gather_all().collect();
169-
170-
let internal_lints = Lint::internal_lints(lint_list.clone().into_iter());
171-
172-
let usable_lints: Vec<Lint> = Lint::usable_lints(lint_list.clone().into_iter()).collect();
173-
let usable_lint_count = usable_lints.len();
174-
175-
let mut sorted_usable_lints = usable_lints.clone();
176-
sorted_usable_lints.sort_by_key(|lint| lint.name.clone());
177-
178-
let mut file_change = replace_region_in_file(
179-
Path::new("src/lintlist/mod.rs"),
180-
"begin lint list",
181-
"end lint list",
182-
false,
183-
update_mode == UpdateMode::Change,
184-
|| {
185-
format!(
186-
"pub const ALL_LINTS: [Lint; {}] = {:#?};",
187-
sorted_usable_lints.len(),
188-
sorted_usable_lints
189-
)
190-
.lines()
191-
.map(ToString::to_string)
192-
.collect::<Vec<_>>()
193-
},
194-
)
195-
.changed;
196-
197-
file_change |= replace_region_in_file(
198-
Path::new("README.md"),
199-
&format!(r#"\[There are \d+ lints included in this crate!\]\({}\)"#, DOCS_LINK),
200-
"",
201-
true,
202-
update_mode == UpdateMode::Change,
203-
|| {
204-
vec![format!(
205-
"[There are {} lints included in this crate!]({})",
206-
usable_lint_count, DOCS_LINK
207-
)]
115+
("limit_stderr_length", _) => {
116+
stderr_length_check::check();
208117
},
209-
)
210-
.changed;
211-
212-
file_change |= replace_region_in_file(
213-
Path::new("CHANGELOG.md"),
214-
"<!-- begin autogenerated links to lint list -->",
215-
"<!-- end autogenerated links to lint list -->",
216-
false,
217-
update_mode == UpdateMode::Change,
218-
|| gen_changelog_lint_list(lint_list.clone()),
219-
)
220-
.changed;
221-
222-
file_change |= replace_region_in_file(
223-
Path::new("clippy_lints/src/lib.rs"),
224-
"begin deprecated lints",
225-
"end deprecated lints",
226-
false,
227-
update_mode == UpdateMode::Change,
228-
|| gen_deprecated(&lint_list),
229-
)
230-
.changed;
231-
232-
file_change |= replace_region_in_file(
233-
Path::new("clippy_lints/src/lib.rs"),
234-
"begin register lints",
235-
"end register lints",
236-
false,
237-
update_mode == UpdateMode::Change,
238-
|| gen_register_lint_list(&lint_list),
239-
)
240-
.changed;
241-
242-
file_change |= replace_region_in_file(
243-
Path::new("clippy_lints/src/lib.rs"),
244-
"begin lints modules",
245-
"end lints modules",
246-
false,
247-
update_mode == UpdateMode::Change,
248-
|| gen_modules_list(lint_list.clone()),
249-
)
250-
.changed;
251-
252-
// Generate lists of lints in the clippy::all lint group
253-
file_change |= replace_region_in_file(
254-
Path::new("clippy_lints/src/lib.rs"),
255-
r#"store.register_group\(true, "clippy::all""#,
256-
r#"\]\);"#,
257-
false,
258-
update_mode == UpdateMode::Change,
259-
|| {
260-
// clippy::all should only include the following lint groups:
261-
let all_group_lints = usable_lints
262-
.clone()
263-
.into_iter()
264-
.filter(|l| {
265-
l.group == "correctness" || l.group == "style" || l.group == "complexity" || l.group == "perf"
266-
})
267-
.collect();
268-
269-
gen_lint_group_list(all_group_lints)
270-
},
271-
)
272-
.changed;
273-
274-
// Generate the list of lints for all other lint groups
275-
for (lint_group, lints) in Lint::by_lint_group(usable_lints.into_iter().chain(internal_lints)) {
276-
file_change |= replace_region_in_file(
277-
Path::new("clippy_lints/src/lib.rs"),
278-
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
279-
r#"\]\);"#,
280-
false,
281-
update_mode == UpdateMode::Change,
282-
|| gen_lint_group_list(lints.clone()),
283-
)
284-
.changed;
285-
}
286-
287-
if update_mode == UpdateMode::Check && file_change {
288-
println!(
289-
"Not all lints defined properly. \
290-
Please run `cargo dev update_lints` to make sure all lints are defined properly."
291-
);
292-
std::process::exit(1);
118+
_ => {},
293119
}
294120
}

clippy_dev/src/new_lint.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1-
use clippy_dev::clippy_project_root;
1+
use crate::clippy_project_root;
22
use std::fs::{File, OpenOptions};
33
use std::io;
44
use std::io::prelude::*;
55
use std::io::ErrorKind;
66
use std::path::Path;
77

8+
/// Creates files required to implement and test a new lint and runs `update_lints`.
9+
///
10+
/// # Errors
11+
///
12+
/// This function errors, if the files couldn't be created
813
pub fn create(pass: Option<&str>, lint_name: Option<&str>, category: Option<&str>) -> Result<(), io::Error> {
914
let pass = pass.expect("`pass` argument is validated by clap");
1015
let lint_name = lint_name.expect("`name` argument is validated by clap");

clippy_dev/src/stderr_length_check.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1+
use crate::clippy_project_root;
12
use std::ffi::OsStr;
23
use std::fs;
34
use std::path::{Path, PathBuf};
4-
55
use walkdir::WalkDir;
66

7-
use clippy_dev::clippy_project_root;
8-
97
// The maximum length allowed for stderr files.
108
//
119
// We limit this because small files are easier to deal with than bigger files.

0 commit comments

Comments
 (0)