Skip to content

Commit

Permalink
refactor(cli): Clarify role of checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ed Page committed Mar 1, 2021
1 parent b5f606f commit 0ea6de6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
18 changes: 9 additions & 9 deletions benches/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod data;

use assert_fs::prelude::*;
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion};
use typos_cli::checks::FileChecker;
use typos_cli::file::FileChecker;

fn bench_checks(c: &mut Criterion) {
let mut group = c.benchmark_group("checks");
Expand All @@ -15,9 +15,9 @@ fn bench_checks(c: &mut Criterion) {

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::checks::CheckSettings::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::checks::FoundFiles.check_file(
typos_cli::file::FoundFiles.check_file(
sample_path.path(),
true,
&settings,
Expand All @@ -36,9 +36,9 @@ fn bench_checks(c: &mut Criterion) {

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::checks::CheckSettings::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::checks::Identifiers.check_file(
typos_cli::file::Identifiers.check_file(
sample_path.path(),
true,
&settings,
Expand All @@ -57,9 +57,9 @@ fn bench_checks(c: &mut Criterion) {

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::checks::CheckSettings::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::checks::Words.check_file(
typos_cli::file::Words.check_file(
sample_path.path(),
true,
&settings,
Expand All @@ -78,9 +78,9 @@ fn bench_checks(c: &mut Criterion) {

let corrections = typos_cli::dict::BuiltIn::new(Default::default());
let parser = typos::tokens::Tokenizer::new();
let settings = typos_cli::checks::CheckSettings::new();
let settings = typos_cli::file::CheckSettings::new();
b.iter(|| {
typos_cli::checks::Typos.check_file(
typos_cli::file::Typos.check_file(
sample_path.path(),
true,
&settings,
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod checks;
pub mod config;
pub mod dict;
pub mod file;
pub mod report;
21 changes: 10 additions & 11 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::io::Write;
use structopt::StructOpt;

mod args;
use typos_cli::checks;
use typos_cli::config;
use typos_cli::dict;
use typos_cli::report;
Expand Down Expand Up @@ -105,7 +104,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
dictionary.identifiers(config.default.extend_identifiers());
dictionary.words(config.default.extend_words());

let mut settings = checks::CheckSettings::new();
let mut settings = typos_cli::file::CheckSettings::new();
settings
.check_filenames(config.default.check_filename())
.check_files(config.default.check_file())
Expand All @@ -132,22 +131,22 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let status_reporter = report::MessageStatus::new(output_reporter);
let reporter: &dyn report::Report = &status_reporter;

let selected_checks: &dyn checks::FileChecker = if args.files {
&checks::FoundFiles
let selected_checks: &dyn typos_cli::file::FileChecker = if args.files {
&typos_cli::file::FoundFiles
} else if args.identifiers {
&checks::Identifiers
&typos_cli::file::Identifiers
} else if args.words {
&checks::Words
&typos_cli::file::Words
} else if args.write_changes {
&checks::FixTypos
&typos_cli::file::FixTypos
} else if args.diff {
&checks::DiffTypos
&typos_cli::file::DiffTypos
} else {
&checks::Typos
&typos_cli::file::Typos
};

if single_threaded {
checks::walk_path(
typos_cli::file::walk_path(
walk.build(),
selected_checks,
&settings,
Expand All @@ -156,7 +155,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
reporter,
)
} else {
checks::walk_path_parallel(
typos_cli::file::walk_path_parallel(
walk.build_parallel(),
selected_checks,
&settings,
Expand Down

0 comments on commit 0ea6de6

Please sign in to comment.