From c9754475d6d466f2c7f85a061f9990443d47f20e Mon Sep 17 00:00:00 2001 From: ANSHUL SINGH Date: Sat, 19 Sep 2026 17:34:50 +0000 Subject: [PATCH] Document a non-greedy --ignore-multiline-regex example The help text used a greedy .* which matches from the first codespell:ignore-begin through the last ignore-end, so typos between two ignored regions are silently skipped. Use .*? in the documented example and cover that case in tests. --- codespell_lib/_codespell.py | 2 +- codespell_lib/tests/test_basic.py | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 1ec09fdf8f..57bad5436d 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -491,7 +491,7 @@ def convert_arg_line_to_args(self, arg_line: str) -> list[str]: "allow skipping of regions of Python code using " "begin/end comments one could use: " "--ignore-multiline-regex " - "'# codespell:ignore-begin *\\n.*# codespell:ignore-end *\\n'. " + "'# codespell:ignore-begin *\\n.*?# codespell:ignore-end *\\n'. " "Defaults to empty/disabled.", ) parser.add_argument( diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 0127f57013..8be7186b07 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -1156,6 +1156,21 @@ def test_ignore_multiline_regex_option( """ assert fname.read_text() == fixed_text + # The documented example uses a non-greedy match so a typo between two + # ignore regions is still reported (a greedy .* would swallow it). + two_blocks = """ + # codespell:ignore-begin + abandonned + # codespell:ignore-end + abandonned + # codespell:ignore-begin + abandonned + # codespell:ignore-end + """ + fname.write_text(two_blocks) + documented = r"# codespell:ignore-begin *\n.*?# codespell:ignore-end *\n" + assert cs.main(fname, "--ignore-multiline-regex", documented) == 1 + def test_uri_regex_option( tmp_path: Path,