Skip to content

Commit

Permalink
refactor(cli): Clarify role of file config
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Apr 1, 2021
1 parent a148054 commit 47eb554
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
14 changes: 7 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
22 changes: 10 additions & 12 deletions src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>>,
}
Expand All @@ -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(),
}
Expand All @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -223,7 +221,7 @@ impl<T> Default for Intern<T> {
}

struct DirConfig {
files: usize,
walk: usize,
tokenizer: usize,
dict: usize,
check_filenames: bool,
Expand Down

0 comments on commit 47eb554

Please sign in to comment.