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

Add "--force-exclude" option #837

Merged
merged 2 commits into from
Oct 9, 2023
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
6 changes: 3 additions & 3 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
description: Source code spell checker, binary install
language: python
entry: typos
args: [--write-changes]
args: [--write-changes, --force-exclude]
types: [text]
stages: [commit, merge-commit, push, manual]

Expand All @@ -12,7 +12,7 @@
description: Source code spell checker, Docker image
language: docker
entry: typos
args: [--write-changes]
args: [--write-changes, --force-exclude]
types: [text]
stages: [commit, merge-commit, push, manual]

Expand All @@ -21,6 +21,6 @@
description: Source code spell checker, source install
language: rust
entry: typos
args: [--write-changes]
args: [--write-changes, --force-exclude]
types: [text]
stages: [commit, merge-commit, push, manual]
4 changes: 4 additions & 0 deletions crates/typos-cli/src/bin/typos-cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ pub(crate) struct Args {
#[arg(short = 'j', long = "threads", default_value = "0")]
pub(crate) threads: usize,

/// Respect excluded files even for paths passed explicitly.
#[arg(long, help_heading = None)]
pub(crate) force_exclude: bool,

/// Custom config file
#[arg(short = 'c', long = "config", help_heading = "Config")]
pub(crate) custom_config: Option<std::path::PathBuf>,
Expand Down
5 changes: 5 additions & 0 deletions crates/typos-cli/src/bin/typos-cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ fn run_checks(args: &args::Args) -> proc_exit::ExitResult {
let overrides = overrides
.build()
.with_code(proc_exit::sysexits::CONFIG_ERR)?;
if args.force_exclude {
if let ignore::Match::Ignore(_) = overrides.matched(path, path.is_dir()) {
continue;
}
}
walk.overrides(overrides);
}

Expand Down
5 changes: 5 additions & 0 deletions crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[files]
extend-exclude = ["file.ignore"]

[default.extend-identifiers]
hello = "goodbye"
1 change: 1 addition & 0 deletions crates/typos-cli/tests/cmd/force-exclude.in/file.ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello
6 changes: 6 additions & 0 deletions crates/typos-cli/tests/cmd/force-exclude.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bin.name = "typos"
args = "file.ignore --force-exclude"
epage marked this conversation as resolved.
Show resolved Hide resolved
stdin = ""
stdout = ""
stderr = ""
status.code = 0
1 change: 1 addition & 0 deletions crates/typos-cli/tests/cmd/help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Arguments:

Options:
-j, --threads <THREADS> The approximate number of threads to use [default: 0]
--force-exclude Respect excluded files even for paths passed explicitly
-h, --help Print help
-V, --version Print version

Expand Down
1 change: 1 addition & 0 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Configuration is read from the following (in precedence order)
|------------------------|-------------------|--------|-------------|
| files.binary | --binary | bool | Check binary files as text |
| files.extend-exclude | --exclude | list of strings | Typos-specific ignore globs (gitignore syntax) |
| file.force-excude | --force-exclude | bool | Respect excluded files even for paths passed explicitly. |
| 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