Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ignore): Typos=specific ignores #255

Merged
merged 1 commit into from May 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/reference.md
Expand Up @@ -14,6 +14,8 @@ Configuration is read from the following (in precedence order)

| Field | Argument | Format | Description |
|------------------------|-------------------|--------|-------------|
| files.binary | --binary | bool | Check binary files as text |
| files.extend-exclude | --exclude | list of strings | Typos-specific ignore globs (gitignore syntax) |
| 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. |
Expand Down
5 changes: 5 additions & 0 deletions src/bin/typos-cli/args.rs
Expand Up @@ -200,6 +200,10 @@ impl ConfigArgs {
#[derive(Debug, StructOpt)]
#[structopt(rename_all = "kebab-case")]
pub(crate) struct WalkArgs {
#[structopt(long)]
/// Ignore all files & directories matching the pattern.
exclude: Vec<String>,

#[structopt(long, overrides_with("no-hidden"))]
/// Search hidden files and directories.
hidden: bool,
Expand Down Expand Up @@ -240,6 +244,7 @@ pub(crate) struct WalkArgs {
impl WalkArgs {
pub fn to_config(&self) -> config::Walk {
config::Walk {
extend_exclude: self.exclude.clone(),
ignore_hidden: self.ignore_hidden(),
ignore_files: self.ignore_files(),
ignore_dot: self.ignore_dot(),
Expand Down
10 changes: 10 additions & 0 deletions src/bin/typos-cli/main.rs
Expand Up @@ -196,6 +196,16 @@ fn run_checks(
.git_ignore(walk_policy.ignore_vcs())
.git_exclude(walk_policy.ignore_vcs())
.parents(walk_policy.ignore_parent());
if !walk_policy.extend_exclude.is_empty() {
let mut overrides = ignore::overrides::OverrideBuilder::new(".");
for pattern in walk_policy.extend_exclude.iter() {
overrides
.add(&format!("!{}", pattern))
.with_code(proc_exit::Code::CONFIG_ERR)?;
}
let overrides = overrides.build().with_code(proc_exit::Code::CONFIG_ERR)?;
walk.overrides(overrides);
}

// HACK: Diff doesn't handle mixing content
let output_reporter = if args.diff {
Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Expand Up @@ -61,6 +61,7 @@ impl Config {
#[serde(deny_unknown_fields, default)]
#[serde(rename_all = "kebab-case")]
pub struct Walk {
pub extend_exclude: Vec<String>,
/// Skip hidden files and directories.
pub ignore_hidden: Option<bool>,
/// Respect ignore files.
Expand All @@ -79,6 +80,7 @@ impl Walk {
pub fn from_defaults() -> Self {
let empty = Self::default();
Self {
extend_exclude: empty.extend_exclude.clone(),
ignore_hidden: Some(empty.ignore_hidden()),
ignore_files: Some(true),
ignore_dot: Some(empty.ignore_dot()),
Expand All @@ -89,6 +91,8 @@ impl Walk {
}

pub fn update(&mut self, source: &Walk) {
self.extend_exclude
.extend(source.extend_exclude.iter().cloned());
if let Some(source) = source.ignore_hidden {
self.ignore_hidden = Some(source);
}
Expand All @@ -114,6 +118,10 @@ impl Walk {
}
}

pub fn extend_exclude(&self) -> &[String] {
&self.extend_exclude
}

pub fn ignore_hidden(&self) -> bool {
self.ignore_hidden.unwrap_or(true)
}
Expand Down