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,