From 47eb55405266d41fd7850da90f8e10801b84b8f7 Mon Sep 17 00:00:00 2001 From: Ed Page Date: Wed, 31 Mar 2021 20:06:33 -0500 Subject: [PATCH] refactor(cli): Clarify role of file config --- src/main.rs | 14 +++++++------- src/policy.rs | 22 ++++++++++------------ 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5cddf7c..886337a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -114,19 +114,19 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult { engine .init_dir(cwd) .with_code(proc_exit::Code::CONFIG_ERR)?; - let files = engine.files(cwd); + let walk_policy = engine.walk(cwd); let threads = if path.is_file() { 1 } else { args.threads }; let single_threaded = threads == 1; let mut walk = ignore::WalkBuilder::new(path); walk.threads(args.threads) - .hidden(files.ignore_hidden()) - .ignore(files.ignore_dot()) - .git_global(files.ignore_global()) - .git_ignore(files.ignore_vcs()) - .git_exclude(files.ignore_vcs()) - .parents(files.ignore_parent()); + .hidden(walk_policy.ignore_hidden()) + .ignore(walk_policy.ignore_dot()) + .git_global(walk_policy.ignore_global()) + .git_ignore(walk_policy.ignore_vcs()) + .git_exclude(walk_policy.ignore_vcs()) + .parents(walk_policy.ignore_parent()); // HACK: Diff doesn't handle mixing content let output_reporter = if args.diff { diff --git a/src/policy.rs b/src/policy.rs index 92c8aa6..3a27c0f 100644 --- a/src/policy.rs +++ b/src/policy.rs @@ -40,7 +40,7 @@ pub struct ConfigEngine<'s> { isolated: bool, configs: std::collections::HashMap, - files: Intern, + walk: Intern, tokenizer: Intern, dict: Intern>, } @@ -53,7 +53,7 @@ impl<'s> ConfigEngine<'s> { custom: Default::default(), configs: Default::default(), isolated: false, - files: Default::default(), + walk: Default::default(), tokenizer: Default::default(), dict: Default::default(), } @@ -74,18 +74,16 @@ impl<'s> ConfigEngine<'s> { self } - pub fn files(&mut self, cwd: &std::path::Path) -> &crate::config::Walk { + pub fn walk(&mut self, cwd: &std::path::Path) -> &crate::config::Walk { let dir = self .configs .get(cwd) .expect("`init_dir` must be called first"); - self.get_files(dir) + self.get_walk(dir) } pub fn policy(&self, path: &std::path::Path) -> Policy<'_, '_> { - let dir = self - .get_dir(path) - .expect("`files()` should be called first"); + let dir = self.get_dir(path).expect("`walk()` should be called first"); Policy { check_filenames: dir.check_filenames, check_files: dir.check_files, @@ -95,8 +93,8 @@ impl<'s> ConfigEngine<'s> { } } - fn get_files(&self, dir: &DirConfig) -> &crate::config::Walk { - self.files.get(dir.files) + fn get_walk(&self, dir: &DirConfig) -> &crate::config::Walk { + self.walk.get(dir.walk) } fn get_tokenizer(&self, dir: &DirConfig) -> &typos::tokens::Tokenizer { @@ -177,11 +175,11 @@ impl<'s> ConfigEngine<'s> { ); let dict = self.dict.intern(dict); - let files = self.files.intern(files); + let walk = self.walk.intern(files); let tokenizer = self.tokenizer.intern(tokenizer); let dir = DirConfig { - files, + walk, check_filenames: check_filename, check_files: check_file, binary, @@ -223,7 +221,7 @@ impl Default for Intern { } struct DirConfig { - files: usize, + walk: usize, tokenizer: usize, dict: usize, check_filenames: bool,