Skip to content

Commit 5eb4665

Browse files
authored
Merge pull request #255 from epage/ignore
feat(ignore): Typos=specific ignores
2 parents 0cf1675 + 327a84a commit 5eb4665

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

docs/reference.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Configuration is read from the following (in precedence order)
1414

1515
| Field | Argument | Format | Description |
1616
|------------------------|-------------------|--------|-------------|
17+
| files.binary | --binary | bool | Check binary files as text |
18+
| files.extend-exclude | --exclude | list of strings | Typos-specific ignore globs (gitignore syntax) |
1719
| files.ignore-hidden | --hidden | bool | Skip hidden files and directories. |
1820
| files.ignore-files | --ignore | bool | Respect ignore files. |
1921
| files.ignore-dot | --ignore-dot | bool | Respect .ignore files. |

src/bin/typos-cli/args.rs

+5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ impl ConfigArgs {
200200
#[derive(Debug, StructOpt)]
201201
#[structopt(rename_all = "kebab-case")]
202202
pub(crate) struct WalkArgs {
203+
#[structopt(long)]
204+
/// Ignore all files & directories matching the pattern.
205+
exclude: Vec<String>,
206+
203207
#[structopt(long, overrides_with("no-hidden"))]
204208
/// Search hidden files and directories.
205209
hidden: bool,
@@ -240,6 +244,7 @@ pub(crate) struct WalkArgs {
240244
impl WalkArgs {
241245
pub fn to_config(&self) -> config::Walk {
242246
config::Walk {
247+
extend_exclude: self.exclude.clone(),
243248
ignore_hidden: self.ignore_hidden(),
244249
ignore_files: self.ignore_files(),
245250
ignore_dot: self.ignore_dot(),

src/bin/typos-cli/main.rs

+10
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ fn run_checks(
196196
.git_ignore(walk_policy.ignore_vcs())
197197
.git_exclude(walk_policy.ignore_vcs())
198198
.parents(walk_policy.ignore_parent());
199+
if !walk_policy.extend_exclude.is_empty() {
200+
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
201+
for pattern in walk_policy.extend_exclude.iter() {
202+
overrides
203+
.add(&format!("!{}", pattern))
204+
.with_code(proc_exit::Code::CONFIG_ERR)?;
205+
}
206+
let overrides = overrides.build().with_code(proc_exit::Code::CONFIG_ERR)?;
207+
walk.overrides(overrides);
208+
}
199209

200210
// HACK: Diff doesn't handle mixing content
201211
let output_reporter = if args.diff {

src/config.rs

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ impl Config {
6161
#[serde(deny_unknown_fields, default)]
6262
#[serde(rename_all = "kebab-case")]
6363
pub struct Walk {
64+
pub extend_exclude: Vec<String>,
6465
/// Skip hidden files and directories.
6566
pub ignore_hidden: Option<bool>,
6667
/// Respect ignore files.
@@ -79,6 +80,7 @@ impl Walk {
7980
pub fn from_defaults() -> Self {
8081
let empty = Self::default();
8182
Self {
83+
extend_exclude: empty.extend_exclude.clone(),
8284
ignore_hidden: Some(empty.ignore_hidden()),
8385
ignore_files: Some(true),
8486
ignore_dot: Some(empty.ignore_dot()),
@@ -89,6 +91,8 @@ impl Walk {
8991
}
9092

9193
pub fn update(&mut self, source: &Walk) {
94+
self.extend_exclude
95+
.extend(source.extend_exclude.iter().cloned());
9296
if let Some(source) = source.ignore_hidden {
9397
self.ignore_hidden = Some(source);
9498
}
@@ -114,6 +118,10 @@ impl Walk {
114118
}
115119
}
116120

121+
pub fn extend_exclude(&self) -> &[String] {
122+
&self.extend_exclude
123+
}
124+
117125
pub fn ignore_hidden(&self) -> bool {
118126
self.ignore_hidden.unwrap_or(true)
119127
}

0 commit comments

Comments
 (0)