refactor(cli): Clarify role of file config

This commit is contained in:
Ed Page 2021-03-31 20:06:33 -05:00
parent a148054a49
commit 47eb554052
2 changed files with 17 additions and 19 deletions

View file

@ -114,19 +114,19 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
engine engine
.init_dir(cwd) .init_dir(cwd)
.with_code(proc_exit::Code::CONFIG_ERR)?; .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 threads = if path.is_file() { 1 } else { args.threads };
let single_threaded = threads == 1; let single_threaded = threads == 1;
let mut walk = ignore::WalkBuilder::new(path); let mut walk = ignore::WalkBuilder::new(path);
walk.threads(args.threads) walk.threads(args.threads)
.hidden(files.ignore_hidden()) .hidden(walk_policy.ignore_hidden())
.ignore(files.ignore_dot()) .ignore(walk_policy.ignore_dot())
.git_global(files.ignore_global()) .git_global(walk_policy.ignore_global())
.git_ignore(files.ignore_vcs()) .git_ignore(walk_policy.ignore_vcs())
.git_exclude(files.ignore_vcs()) .git_exclude(walk_policy.ignore_vcs())
.parents(files.ignore_parent()); .parents(walk_policy.ignore_parent());
// HACK: Diff doesn't handle mixing content // HACK: Diff doesn't handle mixing content
let output_reporter = if args.diff { let output_reporter = if args.diff {

View file

@ -40,7 +40,7 @@ pub struct ConfigEngine<'s> {
isolated: bool, isolated: bool,
configs: std::collections::HashMap<std::path::PathBuf, DirConfig>, configs: std::collections::HashMap<std::path::PathBuf, DirConfig>,
files: Intern<crate::config::Walk>, walk: Intern<crate::config::Walk>,
tokenizer: Intern<typos::tokens::Tokenizer>, tokenizer: Intern<typos::tokens::Tokenizer>,
dict: Intern<crate::dict::Override<'s, 's, crate::dict::BuiltIn>>, dict: Intern<crate::dict::Override<'s, 's, crate::dict::BuiltIn>>,
} }
@ -53,7 +53,7 @@ impl<'s> ConfigEngine<'s> {
custom: Default::default(), custom: Default::default(),
configs: Default::default(), configs: Default::default(),
isolated: false, isolated: false,
files: Default::default(), walk: Default::default(),
tokenizer: Default::default(), tokenizer: Default::default(),
dict: Default::default(), dict: Default::default(),
} }
@ -74,18 +74,16 @@ impl<'s> ConfigEngine<'s> {
self 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 let dir = self
.configs .configs
.get(cwd) .get(cwd)
.expect("`init_dir` must be called first"); .expect("`init_dir` must be called first");
self.get_files(dir) self.get_walk(dir)
} }
pub fn policy(&self, path: &std::path::Path) -> Policy<'_, '_> { pub fn policy(&self, path: &std::path::Path) -> Policy<'_, '_> {
let dir = self let dir = self.get_dir(path).expect("`walk()` should be called first");
.get_dir(path)
.expect("`files()` should be called first");
Policy { Policy {
check_filenames: dir.check_filenames, check_filenames: dir.check_filenames,
check_files: dir.check_files, check_files: dir.check_files,
@ -95,8 +93,8 @@ impl<'s> ConfigEngine<'s> {
} }
} }
fn get_files(&self, dir: &DirConfig) -> &crate::config::Walk { fn get_walk(&self, dir: &DirConfig) -> &crate::config::Walk {
self.files.get(dir.files) self.walk.get(dir.walk)
} }
fn get_tokenizer(&self, dir: &DirConfig) -> &typos::tokens::Tokenizer { fn get_tokenizer(&self, dir: &DirConfig) -> &typos::tokens::Tokenizer {
@ -177,11 +175,11 @@ impl<'s> ConfigEngine<'s> {
); );
let dict = self.dict.intern(dict); 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 tokenizer = self.tokenizer.intern(tokenizer);
let dir = DirConfig { let dir = DirConfig {
files, walk,
check_filenames: check_filename, check_filenames: check_filename,
check_files: check_file, check_files: check_file,
binary, binary,
@ -223,7 +221,7 @@ impl<T> Default for Intern<T> {
} }
struct DirConfig { struct DirConfig {
files: usize, walk: usize,
tokenizer: usize, tokenizer: usize,
dict: usize, dict: usize,
check_filenames: bool, check_filenames: bool,