From 442b1199da2266e2904fabb8bdb83d52369e5e6a Mon Sep 17 00:00:00 2001 From: Delgan Date: Sat, 7 Oct 2023 22:01:11 +0000 Subject: [PATCH 1/2] Add initial test preparing "--force-exclude" --- .../tests/cmd/force-exclude.in/_typos.toml | 5 +++++ .../tests/cmd/force-exclude.in/file.ignore | 1 + crates/typos-cli/tests/cmd/force-exclude.toml | 13 +++++++++++++ 3 files changed, 19 insertions(+) create mode 100644 crates/typos-cli/tests/cmd/force-exclude.in/_typos.toml create mode 100644 crates/typos-cli/tests/cmd/force-exclude.in/file.ignore create mode 100644 crates/typos-cli/tests/cmd/force-exclude.toml 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..018de63 --- /dev/null +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -0,0 +1,13 @@ +bin.name = "typos" +args = "file.ignore" +stdin = "" +stdout = """ +error: `hello` should be `goodbye` + --> file.ignore:1:1 + | +1 | hello + | ^^^^^ + | +""" +stderr = "" +status.code = 2 From 8314a1567d03ff2b2b2e294c8bb63a4edcdf106a Mon Sep 17 00:00:00 2001 From: Delgan Date: Sat, 7 Oct 2023 22:01:49 +0000 Subject: [PATCH 2/2] Add "--force-exclude" option --- .pre-commit-hooks.yaml | 6 +++--- crates/typos-cli/src/bin/typos-cli/args.rs | 4 ++++ crates/typos-cli/src/bin/typos-cli/main.rs | 5 +++++ crates/typos-cli/tests/cmd/force-exclude.toml | 13 +++---------- crates/typos-cli/tests/cmd/help.toml | 1 + docs/reference.md | 1 + 6 files changed, 17 insertions(+), 13 deletions(-) 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.toml b/crates/typos-cli/tests/cmd/force-exclude.toml index 018de63..863fe82 100644 --- a/crates/typos-cli/tests/cmd/force-exclude.toml +++ b/crates/typos-cli/tests/cmd/force-exclude.toml @@ -1,13 +1,6 @@ bin.name = "typos" -args = "file.ignore" +args = "file.ignore --force-exclude" stdin = "" -stdout = """ -error: `hello` should be `goodbye` - --> file.ignore:1:1 - | -1 | hello - | ^^^^^ - | -""" +stdout = "" stderr = "" -status.code = 2 +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. |