refactor: Consolidate paths

This commit is contained in:
Ed Page 2019-11-15 07:48:07 -07:00
parent 59baa36327
commit b74258a43c

View file

@ -372,6 +372,31 @@ fn init_logging(level: Option<log::Level>) {
} }
} }
fn check_path(
mut walk: ignore::Walk,
format: Format,
checks: &dyn Checks,
parser: &typos::tokens::Parser,
dictionary: &dyn typos::Dictionary,
) -> Result<(bool, bool), anyhow::Error> {
let mut typos_found = false;
let mut errors_found = false;
for entry in walk {
match check_entry(entry, format, checks, parser, dictionary) {
Ok(true) => typos_found = true,
Err(err) => {
let msg = typos::report::Error::new(err.to_string());
format.report()(msg.into());
errors_found = true
}
_ => (),
}
}
Ok((typos_found, errors_found))
}
fn check_entry( fn check_entry(
entry: Result<ignore::DirEntry, ignore::Error>, entry: Result<ignore::DirEntry, ignore::Error>,
format: Format, format: Format,
@ -465,42 +490,33 @@ fn run() -> Result<i32, anyhow::Error> {
} }
} else if args.identifiers { } else if args.identifiers {
let checks = settings.build_identifier_parser(); let checks = settings.build_identifier_parser();
for entry in walk.build() { let (cur_typos, cur_errors) =
match check_entry(entry, args.format, &checks, &parser, &dictionary) { check_path(walk.build(), args.format, &checks, &parser, &dictionary)?;
Ok(true) => typos_found = true, if cur_typos {
Err(err) => { typos_found = true;
let msg = typos::report::Error::new(err.to_string()); }
args.format.report()(msg.into()); if cur_errors {
errors_found = true errors_found = true;
}
_ => (),
}
} }
} else if args.words { } else if args.words {
let checks = settings.build_word_parser(); let checks = settings.build_word_parser();
for entry in walk.build() { let (cur_typos, cur_errors) =
match check_entry(entry, args.format, &checks, &parser, &dictionary) { check_path(walk.build(), args.format, &checks, &parser, &dictionary)?;
Ok(true) => typos_found = true, if cur_typos {
Err(err) => { typos_found = true;
let msg = typos::report::Error::new(err.to_string()); }
args.format.report()(msg.into()); if cur_errors {
errors_found = true errors_found = true;
}
_ => (),
}
} }
} else { } else {
let checks = settings.build_checks(); let checks = settings.build_checks();
for entry in walk.build() { let (cur_typos, cur_errors) =
match check_entry(entry, args.format, &checks, &parser, &dictionary) { check_path(walk.build(), args.format, &checks, &parser, &dictionary)?;
Ok(true) => typos_found = true, if cur_typos {
Err(err) => { typos_found = true;
let msg = typos::report::Error::new(err.to_string()); }
args.format.report()(msg.into()); if cur_errors {
errors_found = true errors_found = true;
}
_ => (),
}
} }
} }
} }