diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index e4fca39..7130a25 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -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] @@ -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] @@ -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] diff --git a/crates/typos-cli/src/bin/typos-cli/args.rs b/crates/typos-cli/src/bin/typos-cli/args.rs index 41230f1..6ccbc69 100644 --- a/crates/typos-cli/src/bin/typos-cli/args.rs +++ b/crates/typos-cli/src/bin/typos-cli/args.rs @@ -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, diff --git a/crates/typos-cli/src/bin/typos-cli/main.rs b/crates/typos-cli/src/bin/typos-cli/main.rs index 37b9967..017da7d 100644 --- a/crates/typos-cli/src/bin/typos-cli/main.rs +++ b/crates/typos-cli/src/bin/typos-cli/main.rs @@ -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); } diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml b/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml new file mode 100644 index 0000000..434f5f6 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml @@ -0,0 +1,5 @@ +[files] +extend-exclude = ["file.ignore"] + +[default.extend-identifiers] +hello = "goodbye" diff --git a/crates/typos-cli/tests/cmd/force-exclude.in/file.ignore b/crates/typos-cli/tests/cmd/force-exclude.in/file.ignore new file mode 100644 index 0000000..ce01362 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.in/file.ignore @@ -0,0 +1 @@ +hello diff --git a/crates/typos-cli/tests/cmd/force-exclude.toml b/crates/typos-cli/tests/cmd/force-exclude.toml new file mode 100644 index 0000000..863fe82 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -0,0 +1,6 @@ +bin.name = "typos" +args = "file.ignore --force-exclude" +stdin = "" +stdout = "" +stderr = "" +status.code = 0 diff --git a/crates/typos-cli/tests/cmd/help.toml b/crates/typos-cli/tests/cmd/help.toml index 9601e2f..2396e1f 100644 --- a/crates/typos-cli/tests/cmd/help.toml +++ b/crates/typos-cli/tests/cmd/help.toml @@ -10,6 +10,7 @@ Arguments: Options: -j, --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 diff --git a/docs/reference.md b/docs/reference.md index 4b7e792..122de27 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -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. |