Skip to content

Commit eb683e6

Browse files
authored
Merge pull request #3320 from phansch/riir_update_lints_use_walkdir
RIIR update_lints: use WalkDir instead of read_dir
2 parents 78cd2c8 + b5dd8f1 commit eb683e6

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

clippy_dev/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ clap = "~2.32"
99
itertools = "0.7"
1010
regex = "1"
1111
lazy_static = "1.0"
12+
walkdir = "2"

clippy_dev/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use itertools::Itertools;
1515
use lazy_static::lazy_static;
1616
use regex::Regex;
17+
use walkdir::WalkDir;
1718
use std::collections::HashMap;
1819
use std::ffi::OsStr;
1920
use std::fs;
@@ -35,6 +36,7 @@ lazy_static! {
3536
pub static ref DOCS_LINK: String = "https://rust-lang-nursery.github.io/rust-clippy/master/index.html".to_string();
3637
}
3738

39+
/// Lint data parsed from the Clippy source code.
3840
#[derive(Clone, PartialEq, Debug)]
3941
pub struct Lint {
4042
pub name: String,
@@ -66,11 +68,12 @@ impl Lint {
6668
}
6769
}
6870

71+
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
6972
pub fn gather_all() -> impl Iterator<Item=Lint> {
7073
lint_files().flat_map(|f| gather_from_file(&f))
7174
}
7275

73-
fn gather_from_file(dir_entry: &fs::DirEntry) -> impl Iterator<Item=Lint> {
76+
fn gather_from_file(dir_entry: &walkdir::DirEntry) -> impl Iterator<Item=Lint> {
7477
let mut file = fs::File::open(dir_entry.path()).unwrap();
7578
let mut content = String::new();
7679
file.read_to_string(&mut content).unwrap();
@@ -89,9 +92,11 @@ fn parse_contents(content: &str, filename: &str) -> impl Iterator<Item=Lint> {
8992
}
9093

9194
/// Collects all .rs files in the `clippy_lints/src` directory
92-
fn lint_files() -> impl Iterator<Item=fs::DirEntry> {
93-
fs::read_dir("../clippy_lints/src")
94-
.unwrap()
95+
fn lint_files() -> impl Iterator<Item=walkdir::DirEntry> {
96+
// We use `WalkDir` instead of `fs::read_dir` here in order to recurse into subdirectories.
97+
// Otherwise we would not collect all the lints, for example in `clippy_lints/src/methods/`.
98+
WalkDir::new("../clippy_lints/src")
99+
.into_iter()
95100
.filter_map(|f| f.ok())
96101
.filter(|f| f.path().extension() == Some(OsStr::new("rs")))
97102
}

clippy_dev/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn print_lints() {
4444
if lint_group == "Deprecated" { continue; }
4545
println!("\n## {}", lint_group);
4646

47-
lints.sort_by(|a, b| a.name.cmp(&b.name));
47+
lints.sort_by_key(|l| l.name.clone());
4848

4949
for lint in lints {
5050
println!("* [{}]({}#{}) ({})", lint.name, clippy_dev::DOCS_LINK.clone(), lint.name, lint.desc);

0 commit comments

Comments
 (0)