Skip to content

Commit

Permalink
docs(ref): Add dotall specifier to block ignore
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
noahp committed Jun 4, 2024
1 parent d9da472 commit c7a34fc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/typos-cli/tests/cmd/ignore-block.in/_typos.toml
Original file line number Diff line number Diff line change
@@ -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"
6 changes: 5 additions & 1 deletion crates/typos-cli/tests/cmd/ignore-block.in/file.ignore
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions crates/typos-cli/tests/cmd/ignore-block.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
| ^^^^^
|
"""
Expand Down
4 changes: 2 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ Configuration is read from the following (in precedence order)
| type.\<name>.extend-glob | \- | list of strings | File globs for matching `<name>` |

Common `extend-ignore-re`:
- Line ignore with trailing `# spellchecker:disable-line`: `"(?Rm)^.*#\\s*spellchecker:disable-line$"`
- Line block with `# spellchecker:<on|off>`: `"#\\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:<on|off>`: `"(?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"`

0 comments on commit c7a34fc

Please sign in to comment.