Skip to content

Commit 90c6647

Browse files
committed
gen_assists_docs skip hidden files
1 parent 5e827bd commit 90c6647

File tree

3 files changed

+21
-26
lines changed

3 files changed

+21
-26
lines changed

xtask/src/codegen/gen_assists_docs.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::{fs, path::Path};
44

55
use crate::{
66
codegen::{self, extract_comment_blocks_with_empty_lines, Mode},
7-
project_root, Result,
7+
project_root, rust_files, Result,
88
};
99

1010
pub fn generate_assists_docs(mode: Mode) -> Result<()> {
@@ -46,12 +46,8 @@ fn reveal_hash_comments(text: &str) -> String {
4646

4747
fn collect_assists() -> Result<Vec<Assist>> {
4848
let mut res = Vec::new();
49-
for entry in fs::read_dir(project_root().join(codegen::ASSISTS_DIR))? {
50-
let entry = entry?;
51-
let path = entry.path();
52-
if path.is_file() {
53-
collect_file(&mut res, path.as_path())?;
54-
}
49+
for path in rust_files(&project_root().join(codegen::ASSISTS_DIR)) {
50+
collect_file(&mut res, path.as_path())?;
5551
}
5652
res.sort_by(|lhs, rhs| lhs.id.cmp(&rhs.id));
5753
return Ok(res);

xtask/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::{
1717
path::{Path, PathBuf},
1818
process::{Command, Stdio},
1919
};
20+
use walkdir::{DirEntry, WalkDir};
2021

2122
use crate::{
2223
codegen::Mode,
@@ -37,6 +38,21 @@ pub fn project_root() -> PathBuf {
3738
.to_path_buf()
3839
}
3940

41+
pub fn rust_files(path: &Path) -> impl Iterator<Item = PathBuf> {
42+
let iter = WalkDir::new(path);
43+
return iter
44+
.into_iter()
45+
.filter_entry(|e| !is_hidden(e))
46+
.map(|e| e.unwrap())
47+
.filter(|e| !e.file_type().is_dir())
48+
.map(|e| e.into_path())
49+
.filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false));
50+
51+
fn is_hidden(entry: &DirEntry) -> bool {
52+
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
53+
}
54+
}
55+
4056
pub fn run_rustfmt(mode: Mode) -> Result<()> {
4157
let _dir = pushd(project_root());
4258
ensure_rustfmt()?;

xtask/tests/tidy-tests/main.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ use std::{
55
path::{Path, PathBuf},
66
};
77

8-
use walkdir::{DirEntry, WalkDir};
9-
use xtask::{not_bash::fs2, project_root};
8+
use xtask::{not_bash::fs2, project_root, rust_files};
109

1110
#[test]
1211
fn rust_files_are_tidy() {
1312
let mut tidy_docs = TidyDocs::default();
14-
for path in rust_files() {
13+
for path in rust_files(&project_root().join("crates")) {
1514
let text = fs2::read_to_string(&path).unwrap();
1615
check_todo(&path, &text);
1716
check_trailing_ws(&path, &text);
@@ -142,19 +141,3 @@ fn is_exclude_dir(p: &Path, dirs_to_exclude: &[&str]) -> bool {
142141

143142
false
144143
}
145-
146-
fn rust_files() -> impl Iterator<Item = PathBuf> {
147-
let crates = project_root().join("crates");
148-
let iter = WalkDir::new(crates);
149-
return iter
150-
.into_iter()
151-
.filter_entry(|e| !is_hidden(e))
152-
.map(|e| e.unwrap())
153-
.filter(|e| !e.file_type().is_dir())
154-
.map(|e| e.into_path())
155-
.filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false));
156-
157-
fn is_hidden(entry: &DirEntry) -> bool {
158-
entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false)
159-
}
160-
}

0 commit comments

Comments
 (0)