From c7a34fcbe29e491ced257041abe7d2c927c4b415 Mon Sep 17 00:00:00 2001 From: Noah Pendleton <2538614+noahp@users.noreply.github.com> Date: Tue, 4 Jun 2024 15:56:21 -0400 Subject: [PATCH] docs(ref): Add dotall specifier to block ignore Needed a `(?s)` to match multiple enclosed newlines. And added a non-greedy modifier and matching test to prevent double blocks from causing intermediate lines to be ignored: ```shell # spellchecker:off should be ignored # spellchecker:on should not be ignored # without non-greedy, this is also ignored # spellchecker:off should be ignored # spellchecker:on ``` --- crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml | 2 +- crates/typos-cli/tests/cmd/ignore-block.in/file.ignore | 6 +++++- crates/typos-cli/tests/cmd/ignore-block.toml | 4 ++-- docs/reference.md | 4 ++-- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml b/crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml index 26f87f5..980d712 100644 --- a/crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml +++ b/crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml @@ -1,5 +1,5 @@ [default] -extend-ignore-re = ["#\\s*spellchecker:off\\s*\\n.*\\n\\s*#\\s*spellchecker:on"] +extend-ignore-re = ["(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on"] [default.extend-identifiers] hello = "goodbye" diff --git a/crates/typos-cli/tests/cmd/ignore-block.in/file.ignore b/crates/typos-cli/tests/cmd/ignore-block.in/file.ignore index f4ffbfc..6b39f6e 100644 --- a/crates/typos-cli/tests/cmd/ignore-block.in/file.ignore +++ b/crates/typos-cli/tests/cmd/ignore-block.in/file.ignore @@ -1,5 +1,9 @@ hello # spellchecker:off hello -# spellchecker:on +henlo +// spellchecker:on hello +// ensure greedy doesn't exclude everything across blocks +# spellchecker:off +# spellchecker:on diff --git a/crates/typos-cli/tests/cmd/ignore-block.toml b/crates/typos-cli/tests/cmd/ignore-block.toml index 402b757..f7229a4 100644 --- a/crates/typos-cli/tests/cmd/ignore-block.toml +++ b/crates/typos-cli/tests/cmd/ignore-block.toml @@ -8,9 +8,9 @@ error: `hello` should be `goodbye` | ^^^^^ | error: `hello` should be `goodbye` - --> ./file.ignore:5:1 + --> ./file.ignore:6:1 | -5 | hello +6 | hello | ^^^^^ | """ diff --git a/docs/reference.md b/docs/reference.md index dfefa6f..ad27850 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -39,8 +39,8 @@ Configuration is read from the following (in precedence order) | type.\.extend-glob | \- | list of strings | File globs for matching `` | Common `extend-ignore-re`: -- Line ignore with trailing `# spellchecker:disable-line`: `"(?Rm)^.*#\\s*spellchecker:disable-line$"` -- Line block with `# spellchecker:`: `"#\\s*spellchecker:off\\s*\\n.*\\n\\s*#\\s*spellchecker:on"` +- Line ignore with trailing `# spellchecker:disable-line`: `"(?Rm)^.*(#|//)\\s*spellchecker:disable-line$"` +- Line block with `# spellchecker:`: `"(?s)(#|//)\\s*spellchecker:off.*?\\n\\s*(#|//)\\s*spellchecker:on"` Common `extend-ignore-identifiers-re`: - SSL Cipher suites: `"\\bTLS_[A-Z0-9_]+(_anon_[A-Z0-9_]+)?\\b"`