1 //! Library used by tidy and other tools.
3 //! This library contains the tidy lints and exposes it
4 //! to be used by tools.
6 use walkdir::{DirEntry, WalkDir};
13 ($e:expr, $p:expr) => (match $e {
15 Err(e) => panic!("{} failed on {} with {}", stringify!($e), ($p).display(), e),
18 ($e:expr) => (match $e {
20 Err(e) => panic!("{} failed with {}", stringify!($e), e),
24 macro_rules! tidy_error {
25 ($bad:expr, $fmt:expr, $($arg:tt)*) => ({
27 eprint!("tidy error: ");
28 eprintln!($fmt, $($arg)*);
42 pub mod unstable_book;
44 fn filter_dirs(path: &Path) -> bool {
46 "src/llvm-emscripten",
53 "src/tools/rust-installer",
56 skip.iter().any(|p| path.ends_with(p))
60 paths: &[&Path], skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)
67 fn walk(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry, &str)) {
68 let mut contents = String::new();
69 walk_no_read(path, skip, &mut |entry| {
71 if t!(File::open(entry.path()), entry.path()).read_to_string(&mut contents).is_err() {
78 fn walk_no_read(path: &Path, skip: &mut dyn FnMut(&Path) -> bool, f: &mut dyn FnMut(&DirEntry)) {
79 let walker = WalkDir::new(path).into_iter()
80 .filter_entry(|e| !skip(e.path()));
82 if let Ok(entry) = entry {
83 if entry.file_type().is_dir() {