diff options
author | Edwin Cheng <[email protected]> | 2021-02-03 14:01:09 +0000 |
---|---|---|
committer | Edwin Cheng <[email protected]> | 2021-02-03 14:01:09 +0000 |
commit | e73ffbf1e59eb05fe8ffe73ce4e1833295c588a5 (patch) | |
tree | 48f6079b55d32e13f355443aa82a5278a9c68a23 /xtask/src | |
parent | 85e1f0905aae762b8d64b52e76bbc6aa5915894b (diff) |
Add cargo file tidy test
Diffstat (limited to 'xtask/src')
-rw-r--r-- | xtask/src/lib.rs | 33 |
1 files changed, 21 insertions, 12 deletions
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<Item = PathBuf> { | |||
38 | rust_files_in(&project_root().join("crates")) | 38 | rust_files_in(&project_root().join("crates")) |
39 | } | 39 | } |
40 | 40 | ||
41 | pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> { | 41 | pub fn cargo_files() -> impl Iterator<Item = PathBuf> { |
42 | let iter = WalkDir::new(path); | 42 | files_in(&project_root(), "toml") |
43 | return iter | 43 | .filter(|path| path.file_name().map(|it| it == "Cargo.toml").unwrap_or(false)) |
44 | .into_iter() | 44 | } |
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 | 45 | ||
51 | fn is_hidden(entry: &DirEntry) -> bool { | 46 | pub fn rust_files_in(path: &Path) -> impl Iterator<Item = PathBuf> { |
52 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | 47 | files_in(path, "rs") |
53 | } | ||
54 | } | 48 | } |
55 | 49 | ||
56 | pub fn run_rustfmt(mode: Mode) -> Result<()> { | 50 | pub fn run_rustfmt(mode: Mode) -> Result<()> { |
@@ -120,3 +114,18 @@ fn date_iso() -> Result<String> { | |||
120 | fn is_release_tag(tag: &str) -> bool { | 114 | fn is_release_tag(tag: &str) -> bool { |
121 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) | 115 | tag.len() == "2020-02-24".len() && tag.starts_with(|c: char| c.is_ascii_digit()) |
122 | } | 116 | } |
117 | |||
118 | fn files_in(path: &Path, ext: &'static str) -> impl Iterator<Item = PathBuf> { | ||
119 | let iter = WalkDir::new(path); | ||
120 | return iter | ||
121 | .into_iter() | ||
122 | .filter_entry(|e| !is_hidden(e)) | ||
123 | .map(|e| e.unwrap()) | ||
124 | .filter(|e| !e.file_type().is_dir()) | ||
125 | .map(|e| e.into_path()) | ||
126 | .filter(move |path| path.extension().map(|it| it == ext).unwrap_or(false)); | ||
127 | |||
128 | fn is_hidden(entry: &DirEntry) -> bool { | ||
129 | entry.file_name().to_str().map(|s| s.starts_with('.')).unwrap_or(false) | ||
130 | } | ||
131 | } | ||