Skip to content

Commit

Permalink
refactor: Clarify names
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Jan 2, 2021
1 parent 692f0ac commit e6a4f49
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion benches/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate test;
mod data;

use assert_fs::prelude::*;
use typos_cli::checks::Check;
use typos_cli::checks::FileChecker;

fn bench_files(data: &str, b: &mut test::Bencher) {
let temp = assert_fs::TempDir::new().unwrap();
Expand Down
30 changes: 15 additions & 15 deletions src/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::report;
use typos::tokens;
use typos::Dictionary;

pub trait Check: Send + Sync {
pub trait FileChecker: Send + Sync {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -106,7 +106,7 @@ pub struct Typos {
binary: bool,
}

impl Check for Typos {
impl FileChecker for Typos {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -168,7 +168,7 @@ pub struct FixTypos {
binary: bool,
}

impl Check for FixTypos {
impl FileChecker for FixTypos {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -253,7 +253,7 @@ pub struct DiffTypos {
binary: bool,
}

impl Check for DiffTypos {
impl FileChecker for DiffTypos {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -370,7 +370,7 @@ pub struct Identifiers {
binary: bool,
}

impl Check for Identifiers {
impl FileChecker for Identifiers {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -424,7 +424,7 @@ pub struct Words {
binary: bool,
}

impl Check for Words {
impl FileChecker for Words {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -476,7 +476,7 @@ pub struct FoundFiles {
binary: bool,
}

impl Check for FoundFiles {
impl FileChecker for FoundFiles {
fn check_file(
&self,
path: &std::path::Path,
Expand Down Expand Up @@ -613,30 +613,30 @@ fn fix_buffer(mut buffer: Vec<u8>, typos: impl Iterator<Item = typos::Typo<'stat
buffer
}

pub fn check_path(
pub fn walk_path(
walk: ignore::Walk,
checks: &dyn Check,
checks: &dyn FileChecker,
parser: &typos::tokens::Tokenizer,
dictionary: &dyn typos::Dictionary,
reporter: &dyn report::Report,
) -> Result<(), ignore::Error> {
for entry in walk {
check_entry(entry, checks, parser, dictionary, reporter)?;
walk_entry(entry, checks, parser, dictionary, reporter)?;
}
Ok(())
}

pub fn check_path_parallel(
pub fn walk_path_parallel(
walk: ignore::WalkParallel,
checks: &dyn Check,
checks: &dyn FileChecker,
parser: &typos::tokens::Tokenizer,
dictionary: &dyn typos::Dictionary,
reporter: &dyn report::Report,
) -> Result<(), ignore::Error> {
let error: std::sync::Mutex<Result<(), ignore::Error>> = std::sync::Mutex::new(Ok(()));
walk.run(|| {
Box::new(|entry: Result<ignore::DirEntry, ignore::Error>| {
match check_entry(entry, checks, parser, dictionary, reporter) {
match walk_entry(entry, checks, parser, dictionary, reporter) {
Ok(()) => ignore::WalkState::Continue,
Err(err) => {
*error.lock().unwrap() = Err(err);
Expand All @@ -649,9 +649,9 @@ pub fn check_path_parallel(
error.into_inner().unwrap()
}

fn check_entry(
fn walk_entry(
entry: Result<ignore::DirEntry, ignore::Error>,
checks: &dyn Check,
checks: &dyn FileChecker,
parser: &typos::tokens::Tokenizer,
dictionary: &dyn typos::Dictionary,
reporter: &dyn report::Report,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ fn run() -> proc_exit::ExitResult {
let reporter: &dyn report::Report = &status_reporter;

let (files, identifier_parser, word_parser, checks, fixer, differ);
let selected_checks: &dyn checks::Check = if args.files {
let selected_checks: &dyn checks::FileChecker = if args.files {
files = settings.build_files();
&files
} else if args.identifiers {
Expand All @@ -122,15 +122,15 @@ fn run() -> proc_exit::ExitResult {
};

if single_threaded {
checks::check_path(
checks::walk_path(
walk.build(),
selected_checks,
&parser,
&dictionary,
reporter,
)
} else {
checks::check_path_parallel(
checks::walk_path_parallel(
walk.build_parallel(),
selected_checks,
&parser,
Expand Down

0 comments on commit e6a4f49

Please sign in to comment.