mirror of
https://github.com/crate-ci/typos.git
synced 2024-12-22 23:52:12 -05:00
fix(config)!: Move binary to file
Seems like it would make sense to allow varying this by directory (when supporting layering) and by file type.
This commit is contained in:
parent
c6a5cc0a7c
commit
1c3acd747a
4 changed files with 35 additions and 35 deletions
|
@ -14,13 +14,13 @@ Configuration is read from the following (in precedence order)
|
|||
|
||||
| Field | Argument | Format | Description |
|
||||
|------------------------|-------------------|--------|-------------|
|
||||
| files.binary | --binary | bool | Check binary files as text |
|
||||
| files.ignore-hidden | --hidden | bool | Skip hidden files and directories. |
|
||||
| files.ignore-files | --ignore | bool | Respect ignore files. |
|
||||
| files.ignore-dot | --ignore-dot | bool | Respect .ignore files. |
|
||||
| files.ignore-vcs | --ignore-vcs | bool | Respect ignore files in vcs directories. |
|
||||
| files.ignore-global | --ignore-global | bool | Respect global ignore files. |
|
||||
| files.ignore-parent | --ignore-parent | bool | Respect ignore files in parent directories. |
|
||||
| default.binary | --binary | bool | Check binary files as text |
|
||||
| default.check-filename | \- | bool | Verifying spelling in file names. |
|
||||
| default.check-file | \- | bool | Verifying spelling in files. |
|
||||
| default.ignore-hex | \- | bool | Do not check identifiers that appear to be hexadecimal values. |
|
||||
|
|
30
src/args.rs
30
src/args.rs
|
@ -104,6 +104,12 @@ pub(crate) struct Args {
|
|||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(rename_all = "kebab-case")]
|
||||
pub(crate) struct FileArgs {
|
||||
#[structopt(long, overrides_with("no-binary"))]
|
||||
/// Search binary files.
|
||||
binary: bool,
|
||||
#[structopt(long, overrides_with("binary"), hidden(true))]
|
||||
no_binary: bool,
|
||||
|
||||
#[structopt(long, overrides_with("check-filenames"))]
|
||||
/// Skip verifying spelling in file names.
|
||||
no_check_filenames: bool,
|
||||
|
@ -130,6 +136,15 @@ pub(crate) struct FileArgs {
|
|||
}
|
||||
|
||||
impl config::FileSource for FileArgs {
|
||||
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 check_filename(&self) -> Option<bool> {
|
||||
match (self.check_filenames, self.no_check_filenames) {
|
||||
(true, false) => Some(true),
|
||||
|
@ -178,12 +193,6 @@ impl config::ConfigSource for ConfigArgs {
|
|||
#[derive(Debug, StructOpt)]
|
||||
#[structopt(rename_all = "kebab-case")]
|
||||
pub(crate) struct WalkArgs {
|
||||
#[structopt(long, overrides_with("no-binary"))]
|
||||
/// Search binary files.
|
||||
binary: bool,
|
||||
#[structopt(long, overrides_with("binary"), hidden(true))]
|
||||
no_binary: bool,
|
||||
|
||||
#[structopt(long, overrides_with("no-hidden"))]
|
||||
/// Search hidden files and directories.
|
||||
hidden: bool,
|
||||
|
@ -222,15 +231,6 @@ pub(crate) 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),
|
||||
|
|
|
@ -12,11 +12,6 @@ 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
|
||||
|
@ -49,6 +44,11 @@ pub trait WalkSource {
|
|||
}
|
||||
|
||||
pub trait FileSource {
|
||||
/// Check binary files.
|
||||
fn binary(&self) -> Option<bool> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Verifying spelling in file names.
|
||||
fn check_filename(&self) -> Option<bool> {
|
||||
None
|
||||
|
@ -157,7 +157,6 @@ 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>,
|
||||
|
@ -170,7 +169,6 @@ impl Walk {
|
|||
pub fn from_defaults() -> Self {
|
||||
let empty = Self::default();
|
||||
Self {
|
||||
binary: Some(empty.binary()),
|
||||
ignore_hidden: Some(empty.ignore_hidden()),
|
||||
ignore_files: Some(true),
|
||||
ignore_dot: Some(empty.ignore_dot()),
|
||||
|
@ -181,9 +179,6 @@ 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);
|
||||
}
|
||||
|
@ -209,10 +204,6 @@ impl Walk {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn binary(&self) -> bool {
|
||||
self.binary.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn ignore_hidden(&self) -> bool {
|
||||
self.ignore_hidden.unwrap_or(true)
|
||||
}
|
||||
|
@ -238,10 +229,6 @@ impl Walk {
|
|||
}
|
||||
|
||||
impl WalkSource for Walk {
|
||||
fn binary(&self) -> Option<bool> {
|
||||
self.binary
|
||||
}
|
||||
|
||||
fn ignore_hidden(&self) -> Option<bool> {
|
||||
self.ignore_hidden
|
||||
}
|
||||
|
@ -271,6 +258,7 @@ impl WalkSource for Walk {
|
|||
#[serde(deny_unknown_fields, default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct FileConfig {
|
||||
pub binary: Option<bool>,
|
||||
pub check_filename: Option<bool>,
|
||||
pub check_file: Option<bool>,
|
||||
pub ignore_hex: Option<bool>,
|
||||
|
@ -287,6 +275,7 @@ impl FileConfig {
|
|||
pub fn from_defaults() -> Self {
|
||||
let empty = Self::default();
|
||||
FileConfig {
|
||||
binary: Some(empty.binary()),
|
||||
check_filename: Some(empty.check_filename()),
|
||||
check_file: Some(empty.check_file()),
|
||||
ignore_hex: Some(empty.ignore_hex()),
|
||||
|
@ -301,6 +290,9 @@ impl FileConfig {
|
|||
}
|
||||
|
||||
pub fn update(&mut self, source: &dyn FileSource) {
|
||||
if let Some(source) = source.binary() {
|
||||
self.binary = Some(source);
|
||||
}
|
||||
if let Some(source) = source.check_filename() {
|
||||
self.check_filename = Some(source);
|
||||
}
|
||||
|
@ -337,6 +329,10 @@ impl FileConfig {
|
|||
);
|
||||
}
|
||||
|
||||
pub fn binary(&self) -> bool {
|
||||
self.binary.unwrap_or(false)
|
||||
}
|
||||
|
||||
pub fn check_filename(&self) -> bool {
|
||||
self.check_filename.unwrap_or(true)
|
||||
}
|
||||
|
@ -387,6 +383,10 @@ impl FileConfig {
|
|||
}
|
||||
|
||||
impl FileSource for FileConfig {
|
||||
fn binary(&self) -> Option<bool> {
|
||||
self.binary
|
||||
}
|
||||
|
||||
fn check_filename(&self) -> Option<bool> {
|
||||
self.check_filename
|
||||
}
|
||||
|
|
|
@ -109,7 +109,7 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
|
|||
settings
|
||||
.check_filenames(config.default.check_filename())
|
||||
.check_files(config.default.check_file())
|
||||
.binary(config.files.binary());
|
||||
.binary(config.default.binary());
|
||||
|
||||
let threads = if path.is_file() { 1 } else { args.threads };
|
||||
let single_threaded = threads == 1;
|
||||
|
|
Loading…
Reference in a new issue