From e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 3 Feb 2021 22:01:09 +0800 Subject: Add cargo file tidy test --- xtask/src/lib.rs | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) (limited to 'xtask/src') diff --git a/xtask/src/lib.rs b/xtask/src/lib.rs index 16b06b853..b19985fb2 100644 --- a/xtask/src/lib.rs +++ b/xtask/src/lib.rs @@ -38,19 +38,13 @@ pub fn rust_files() -> impl Iterator { rust_files_in(&project_root().join("crates")) } -pub fn rust_files_in(path: &Path) -> impl Iterator { - let iter = WalkDir::new(path); - return iter - .into_iter() - .filter_entry(|e| !is_hidden(e)) - .map(|e| e.unwrap()) - .filter(|e| !e.file_type().is_dir()) - .map(|e| e.into_path()) - .filter(|path| path.extension().map(|it| it == "rs").unwrap_or(false)); +pub fn cargo_files() -> impl Iterator { + files_in(&project_root(), "toml") + .filter(|path| path.file_name().map(|it| it == "Cargo.toml").unwrap_or(false)) +} - fn is_hidden(entry: &DirEntry) -> bool { - entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) - } +pub fn rust_files_in(path: &Path) -> impl Iterator { + files_in(path, "rs") } pub fn run_rustfmt(mode: Mode) -> Result<()> { @@ -120,3 +114,18 @@ fn date_iso() -> Result { fn is_release_tag(tag: &str) -> bool { tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) } + +fn files_in(path: &Path, ext: &'static str) -> impl Iterator { + let iter = WalkDir::new(path); + return iter + .into_iter() + .filter_entry(|e| !is_hidden(e)) + .map(|e| e.unwrap()) + .filter(|e| !e.file_type().is_dir()) + .map(|e| e.into_path()) + .filter(move |path| path.extension().map(|it| it == ext).unwrap_or(false)); + + fn is_hidden(entry: &DirEntry) -> bool { + entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) + } +} -- cgit v1.2.3