mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-25 10:31:02 -05:00
refactor(cli): Clarify role of file config
This commit is contained in:
parent
a148054a49
commit
47eb554052
2 changed files with 17 additions and 19 deletions
14
src/main.rs
14
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 {
|
||||
|
|
|
@ -40,7 +40,7 @@ pub struct ConfigEngine<'s> {
|
|||
isolated: bool,
|
||||
|
||||
configs: std::collections::HashMap<std::path::PathBuf, DirConfig>,
|
||||
files: Intern<crate::config::Walk>,
|
||||
walk: Intern<crate::config::Walk>,
|
||||
tokenizer: Intern<typos::tokens::Tokenizer>,
|
||||
dict: Intern<crate::dict::Override<'s, 's, crate::dict::BuiltIn>>,
|
||||
}
|
||||
|
@ -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<T> Default for Intern<T> {
|
|||
}
|
||||
|
||||
struct DirConfig {
|
||||
files: usize,
|
||||
walk: usize,
|
||||
tokenizer: usize,
|
||||
dict: usize,
|
||||
check_filenames: bool,
|
||||
|
|
Loading…
Reference in a new issue