mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 15:42:23 -05:00
feat(config): Expose binary in config file
This commit is contained in:
parent
77603daab5
commit
29ff040fd1
2 changed files with 44 additions and 27 deletions
|
@ -5,6 +5,11 @@ pub trait ConfigSource {
|
|||
}
|
||||
|
||||
pub trait WalkSource {
|
||||
/// Search binary files.
|
||||
fn binary(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Skip hidden files and directories.
|
||||
fn ignore_hidden(&self) -> Option<bool> {
|
||||
None
|
||||
|
@ -81,6 +86,7 @@ impl ConfigSource for Config {
|
|||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct Walk {
|
||||
pub binary: Option<bool>,
|
||||
pub ignore_hidden: Option<bool>,
|
||||
pub ignore_files: Option<bool>,
|
||||
pub ignore_dot: Option<bool>,
|
||||
|
@ -91,6 +97,9 @@ pub struct Walk {
|
|||
|
||||
impl Walk {
|
||||
pub fn update(&mut self, source: &dyn WalkSource) {
|
||||
if let Some(source) = source.binary() {
|
||||
self.binary = Some(source);
|
||||
}
|
||||
if let Some(source) = source.ignore_hidden() {
|
||||
self.ignore_hidden = Some(source);
|
||||
}
|
||||
|
@ -116,6 +125,10 @@ impl Walk {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn binary(&self) -> bool {
|
||||
self.binary.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn ignore_hidden(&self) -> bool {
|
||||
self.ignore_hidden.unwrap_or(true)
|
||||
}
|
||||
|
@ -147,6 +160,10 @@ impl Walk {
|
|||
}
|
||||
|
||||
impl WalkSource for Walk {
|
||||
fn binary(&self) -> Option<bool> {
|
||||
self.binary
|
||||
}
|
||||
|
||||
fn ignore_hidden(&self) -> Option<bool> {
|
||||
self.ignore_hidden
|
||||
}
|
||||
|
|
54
src/main.rs
54
src/main.rs
|
@ -83,12 +83,6 @@ struct Args {
|
|||
)]
|
||||
pub format: Format,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""no-binary""#))]
|
||||
/// Search binary files.
|
||||
binary: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""binary""#), raw(hidden = "true"))]
|
||||
no_binary: bool,
|
||||
|
||||
#[structopt(flatten)]
|
||||
config: ConfigArgs,
|
||||
|
||||
|
@ -127,15 +121,6 @@ impl Args {
|
|||
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn binary(&self) -> Option<bool> {
|
||||
match (self.binary, self.no_binary) {
|
||||
(true, false) => Some(true),
|
||||
(false, true) => Some(false),
|
||||
(false, false) => None,
|
||||
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
|
@ -154,6 +139,12 @@ impl config::ConfigSource for ConfigArgs {
|
|||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(rename_all = "kebab-case")]
|
||||
struct WalkArgs {
|
||||
#[structopt(long, raw(overrides_with = r#""no-binary""#))]
|
||||
/// Search binary files.
|
||||
binary: bool,
|
||||
#[structopt(long, raw(overrides_with = r#""binary""#), raw(hidden = "true"))]
|
||||
no_binary: bool,
|
||||
|
||||
#[structopt(long, raw(overrides_with = r#""no-hidden""#))]
|
||||
/// Search hidden files and directories.
|
||||
hidden: bool,
|
||||
|
@ -200,6 +191,15 @@ struct WalkArgs {
|
|||
}
|
||||
|
||||
impl config::WalkSource for WalkArgs {
|
||||
fn binary(&self) -> Option<bool> {
|
||||
match (self.binary, self.no_binary) {
|
||||
(true, false) => Some(true),
|
||||
(false, true) => Some(false),
|
||||
(false, false) => None,
|
||||
(_, _) => unreachable!("StructOpt should make this impossible"),
|
||||
}
|
||||
}
|
||||
|
||||
fn ignore_hidden(&self) -> Option<bool> {
|
||||
match (self.hidden, self.no_hidden) {
|
||||
(true, false) => Some(false),
|
||||
|
@ -282,18 +282,6 @@ fn run() -> Result<i32, failure::Error> {
|
|||
let mut builder = get_logging(args.verbose.log_level());
|
||||
builder.init();
|
||||
|
||||
let dictionary = typos::BuiltIn::new();
|
||||
|
||||
let parser = typos::tokens::ParserBuilder::new()
|
||||
.ignore_hex(args.ignore_hex().unwrap_or(true))
|
||||
.build();
|
||||
|
||||
let checks = typos::checks::CheckSettings::new()
|
||||
.check_filenames(args.check_filenames().unwrap_or(true))
|
||||
.check_files(args.check_files().unwrap_or(true))
|
||||
.binary(args.binary().unwrap_or(false))
|
||||
.build(&dictionary, &parser);
|
||||
|
||||
let mut config = config::Config::default();
|
||||
if let Some(path) = args.custom_config.as_ref() {
|
||||
let custom = config::Config::from_file(path)?;
|
||||
|
@ -318,6 +306,18 @@ fn run() -> Result<i32, failure::Error> {
|
|||
config.update(&args.config);
|
||||
let config = config;
|
||||
|
||||
let dictionary = typos::BuiltIn::new();
|
||||
|
||||
let parser = typos::tokens::ParserBuilder::new()
|
||||
.ignore_hex(args.ignore_hex().unwrap_or(true))
|
||||
.build();
|
||||
|
||||
let checks = typos::checks::CheckSettings::new()
|
||||
.check_filenames(args.check_filenames().unwrap_or(true))
|
||||
.check_files(args.check_files().unwrap_or(true))
|
||||
.binary(config.files.binary())
|
||||
.build(&dictionary, &parser);
|
||||
|
||||
let mut walk = ignore::WalkBuilder::new(path);
|
||||
walk.hidden(config.files.ignore_hidden())
|
||||
.ignore(config.files.ignore_dot())
|
||||
|
|
Loading…
Reference in a new issue