From 0f6636d9ccbb56ae0b90b26f56ce3df563c9c417 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 11 Jul 2022 17:09:43 +0200 Subject: [PATCH 01/16] Implement inline ignores Fixes #1212 Following @rob-miller's suggestion implement inline ignore hints. E.g. ``` crate // codespell:ignore crate abandonned abondon abilty # codespell:ignore abondon,abilty abandonned abondon abilty # codespell:ignore # to ignore all ``` --- codespell_lib/_codespell.py | 13 ++++++++++- codespell_lib/tests/test_basic.py | 36 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 9ff65144c0..71edad21bf 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -55,6 +55,8 @@ # Pass all misspellings through this translation table to generate # alternative misspellings and fixes. alt_chars = (("'", "’"),) # noqa: RUF001 +inline_ignore_regex = re.compile( + r"[^\w\s] codespell:ignore(?:(?:\s|$)([\w,]*))") USAGE = """ \t%prog [OPTIONS] [file1 file2 ... fileN] """ @@ -974,6 +976,15 @@ def parse_file( if line.rstrip() in exclude_lines: continue + extra_words_to_ignore = set() + match = inline_ignore_regex.search(line) + if match: + extra_words_to_ignore = set( + filter(None, (match.group(1) or "").split(",")) + ) + if not extra_words_to_ignore: + continue + fixed_words = set() asked_for = set() @@ -998,7 +1009,7 @@ def parse_file( if word in ignore_words_cased: continue lword = word.lower() - if lword in misspellings: + if lword in misspellings and lword not in extra_words_to_ignore: # Sometimes we find a 'misspelling' which is actually a valid word # preceded by a string escape sequence. Ignore such cases as # they're usually false alarms; see issue #17 among others. diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index e5cfc018b1..4128ec60c3 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -391,6 +391,42 @@ def test_ignore_word_list( assert cs.main("-Labandonned,someword", "-Labilty", tmp_path) == 1 +@pytest.mark.parametrize('content, expected_error_count', [ + # recommended form + ('abandonned abondon abilty # codespell:ignore abondon', 2), + ('abandonned abondon abilty // codespell:ignore abondon,abilty', 1), + ('abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty', 0), # noqa: E501 + # wildcard form + ('abandonned abondon abilty # codespell:ignore ', 0), + ('abandonned abondon abilty # codespell:ignore', 0), + ('abandonned abondon abilty # codespell:ignore\n', 0), + ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), + # ignore these for safety + ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 3), + ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 3), + ('abandonned abondon abilty # codespell:ignore/noqa: E501\n', 3), + ('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3), + ('abandonned abondon abilty #codespell:ignore\n', 3), + ('abandonned abondon abilty codespell:ignore\n', 3), + ('abandonned abondon abilty codespell:ignore\n', 3), + # showcase different comment markers + ("abandonned abondon abilty ' codespell:ignore\n", 0), + ('abandonned abondon abilty " codespell:ignore\n', 0), + ('abandonned abondon abilty ;; codespell:ignore\n', 0), +]) +def test_inline_ignores( + tmpdir: pytest.TempPathFactory, + capsys: pytest.CaptureFixture[str], + content: str, + expected_error_count: int +) -> None: + d = str(tmpdir) + with open(op.join(d, 'bad.txt'), 'w') as f: + f.write(content) + assert cs.main(d) == expected_error_count + + def test_custom_regex( tmp_path: Path, capsys: pytest.CaptureFixture[str], From 3912f5066570bfd306746274d6ce4672215a5f06 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 11 Jul 2022 20:16:43 +0200 Subject: [PATCH 02/16] Ignore ".pytest_cache" files during GitHub private action --- .github/workflows/codespell-private.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 9e37ad1ca3..0053221df8 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -54,7 +54,7 @@ jobs: # tomli should not be required for the next two steps (and make sure it's not) - run: pip uninstall -yq tomli if: ${{ matrix.no-toml == 'no-toml' }} - - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" + - run: codespell --check-filenames --skip="./.git/*,./.pytest_cache/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" # this file has an error - run: "! codespell codespell_lib/tests/test_basic.py" From 1f7f926b71e186dd1669e32e39d349188ce2ba36 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 11 Jul 2022 20:22:51 +0200 Subject: [PATCH 03/16] Add test ignoring an unused ignore statement --- codespell_lib/tests/test_basic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 4128ec60c3..64af08fd4a 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -396,6 +396,8 @@ def test_ignore_word_list( ('abandonned abondon abilty # codespell:ignore abondon', 2), ('abandonned abondon abilty // codespell:ignore abondon,abilty', 1), ('abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty', 0), # noqa: E501 + # ignore unused ignore + ('abandonned abondon abilty # codespell:ignore nomenklatur', 3), # wildcard form ('abandonned abondon abilty # codespell:ignore ', 0), ('abandonned abondon abilty # codespell:ignore', 0), From 2ad929109035259661b184070c907bd7a492833f Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 11 Jul 2022 20:24:16 +0200 Subject: [PATCH 04/16] Add test with Windows style line endings --- codespell_lib/tests/test_basic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 64af08fd4a..de0d403e9e 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -402,6 +402,7 @@ def test_ignore_word_list( ('abandonned abondon abilty # codespell:ignore ', 0), ('abandonned abondon abilty # codespell:ignore', 0), ('abandonned abondon abilty # codespell:ignore\n', 0), + ('abandonned abondon abilty # codespell:ignore\r\n', 0), ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), # ignore these for safety From 66de6fa4a0349b74e2219b48d8317a2e97eda9cb Mon Sep 17 00:00:00 2001 From: herr kaste Date: Mon, 11 Jul 2022 23:16:25 +0200 Subject: [PATCH 05/16] Rewrite regex to mitigate false positives Assuming "codespell:ignore" itself is within a comment of the current language, only allow another comment after it or expect (typically) the end of the line. T.i. the preceding comment marker, for example `# ` can appear after the `codespell:ignore` instruction. --- codespell_lib/_codespell.py | 5 +++-- codespell_lib/tests/test_basic.py | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 71edad21bf..ec0457b5a9 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -56,7 +56,8 @@ # alternative misspellings and fixes. alt_chars = (("'", "’"),) # noqa: RUF001 inline_ignore_regex = re.compile( - r"[^\w\s] codespell:ignore(?:(?:\s|$)([\w,]*))") + r"([^\w\s]) codespell:ignore(\s(?P[\w,]*))?(\s+\1|$)" +) USAGE = """ \t%prog [OPTIONS] [file1 file2 ... fileN] """ @@ -980,7 +981,7 @@ def parse_file( match = inline_ignore_regex.search(line) if match: extra_words_to_ignore = set( - filter(None, (match.group(1) or "").split(",")) + filter(None, (match.group("words") or "").split(",")) ) if not extra_words_to_ignore: continue diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index de0d403e9e..8859f381cc 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -417,6 +417,9 @@ def test_ignore_word_list( ("abandonned abondon abilty ' codespell:ignore\n", 0), ('abandonned abondon abilty " codespell:ignore\n', 0), ('abandonned abondon abilty ;; codespell:ignore\n', 0), + ('abandonned abondon abilty /* codespell:ignore */\n', 0), + # avoid false positive + ('You could also use line based igore ( codespell:ignore ) to igore ', 2), ]) def test_inline_ignores( tmpdir: pytest.TempPathFactory, From ce8b2cb8fc04acb6a61834e683c3bb16fc709041 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 22 Jul 2022 14:43:00 +0200 Subject: [PATCH 06/16] Simplified regex which works nice on prose --- codespell_lib/_codespell.py | 2 +- codespell_lib/tests/test_basic.py | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index ec0457b5a9..caaeae6984 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -56,7 +56,7 @@ # alternative misspellings and fixes. alt_chars = (("'", "’"),) # noqa: RUF001 inline_ignore_regex = re.compile( - r"([^\w\s]) codespell:ignore(\s(?P[\w,]*))?(\s+\1|$)" + r"[^\w\s]\s?codespell:ignore\b(\s+(?P[\w,]*))?" ) USAGE = """ \t%prog [OPTIONS] [file1 file2 ... fileN] diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 8859f381cc..156252ea28 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -405,12 +405,11 @@ def test_ignore_word_list( ('abandonned abondon abilty # codespell:ignore\r\n', 0), ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 0), + ('abandonned abondon abilty #codespell:ignore\n', 0), # ignore these for safety - ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 3), - ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 3), - ('abandonned abondon abilty # codespell:ignore/noqa: E501\n', 3), ('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3), - ('abandonned abondon abilty #codespell:ignore\n', 3), ('abandonned abondon abilty codespell:ignore\n', 3), ('abandonned abondon abilty codespell:ignore\n', 3), # showcase different comment markers @@ -418,8 +417,11 @@ def test_ignore_word_list( ('abandonned abondon abilty " codespell:ignore\n', 0), ('abandonned abondon abilty ;; codespell:ignore\n', 0), ('abandonned abondon abilty /* codespell:ignore */\n', 0), - # avoid false positive - ('You could also use line based igore ( codespell:ignore ) to igore ', 2), + # prose examples + ('You could also use line based igore ( codespell:ignore ) to igore ', 0), + ('You could also use line based igore (codespell:ignore) to igore ', 0), + ('You could also use line based igore (codespell:ignore igore) to igore ', 0), # noqa: E501 + ('You could also use line based igore (codespell:ignore igare) to igore ', 2), # noqa: E501 ]) def test_inline_ignores( tmpdir: pytest.TempPathFactory, From 86e36916da7c5db7c14724504b8ea3711c2ba1d1 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 18 Feb 2023 00:54:24 +0100 Subject: [PATCH 07/16] Blacken --- codespell_lib/_codespell.py | 4 +- codespell_lib/tests/test_basic.py | 81 ++++++++++++++++++------------- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index caaeae6984..2db9692242 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -55,9 +55,7 @@ # Pass all misspellings through this translation table to generate # alternative misspellings and fixes. alt_chars = (("'", "’"),) # noqa: RUF001 -inline_ignore_regex = re.compile( - r"[^\w\s]\s?codespell:ignore\b(\s+(?P[\w,]*))?" -) +inline_ignore_regex = re.compile(r"[^\w\s]\s?codespell:ignore\b(\s+(?P[\w,]*))?") USAGE = """ \t%prog [OPTIONS] [file1 file2 ... fileN] """ diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 156252ea28..46308207a0 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -391,43 +391,58 @@ def test_ignore_word_list( assert cs.main("-Labandonned,someword", "-Labilty", tmp_path) == 1 -@pytest.mark.parametrize('content, expected_error_count', [ - # recommended form - ('abandonned abondon abilty # codespell:ignore abondon', 2), - ('abandonned abondon abilty // codespell:ignore abondon,abilty', 1), - ('abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty', 0), # noqa: E501 - # ignore unused ignore - ('abandonned abondon abilty # codespell:ignore nomenklatur', 3), - # wildcard form - ('abandonned abondon abilty # codespell:ignore ', 0), - ('abandonned abondon abilty # codespell:ignore', 0), - ('abandonned abondon abilty # codespell:ignore\n', 0), - ('abandonned abondon abilty # codespell:ignore\r\n', 0), - ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 0), - ('abandonned abondon abilty #codespell:ignore\n', 0), - # ignore these for safety - ('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3), - ('abandonned abondon abilty codespell:ignore\n', 3), - ('abandonned abondon abilty codespell:ignore\n', 3), - # showcase different comment markers - ("abandonned abondon abilty ' codespell:ignore\n", 0), - ('abandonned abondon abilty " codespell:ignore\n', 0), - ('abandonned abondon abilty ;; codespell:ignore\n', 0), - ('abandonned abondon abilty /* codespell:ignore */\n', 0), - # prose examples - ('You could also use line based igore ( codespell:ignore ) to igore ', 0), - ('You could also use line based igore (codespell:ignore) to igore ', 0), - ('You could also use line based igore (codespell:ignore igore) to igore ', 0), # noqa: E501 - ('You could also use line based igore (codespell:ignore igare) to igore ', 2), # noqa: E501 -]) +@pytest.mark.parametrize( + 'content, expected_error_count', + [ + # recommended form + ('abandonned abondon abilty # codespell:ignore abondon', 2), + ('abandonned abondon abilty // codespell:ignore abondon,abilty', 1), + ( + 'abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty', + 0, + ), # noqa: E501 + # ignore unused ignore + ('abandonned abondon abilty # codespell:ignore nomenklatur', 3), + # wildcard form + ('abandonned abondon abilty # codespell:ignore ', 0), + ('abandonned abondon abilty # codespell:ignore', 0), + ('abandonned abondon abilty # codespell:ignore\n', 0), + ('abandonned abondon abilty # codespell:ignore\r\n', 0), + ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 0), + ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 0), + ('abandonned abondon abilty #codespell:ignore\n', 0), + # ignore these for safety + ('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3), + ('abandonned abondon abilty codespell:ignore\n', 3), + ('abandonned abondon abilty codespell:ignore\n', 3), + # showcase different comment markers + ("abandonned abondon abilty ' codespell:ignore\n", 0), + ('abandonned abondon abilty " codespell:ignore\n', 0), + ('abandonned abondon abilty ;; codespell:ignore\n', 0), + ('abandonned abondon abilty /* codespell:ignore */\n', 0), + # prose examples + ( + 'You could also use line based igore ( codespell:ignore ) to igore ', + 0, + ), + ('You could also use line based igore (codespell:ignore) to igore ', 0), + ( + 'You could also use line based igore (codespell:ignore igore) to igore ', + 0, + ), # noqa: E501 + ( + 'You could also use line based igore (codespell:ignore igare) to igore ', + 2, + ), # noqa: E501 + ], +) def test_inline_ignores( tmpdir: pytest.TempPathFactory, capsys: pytest.CaptureFixture[str], content: str, - expected_error_count: int + expected_error_count: int, ) -> None: d = str(tmpdir) with open(op.join(d, 'bad.txt'), 'w') as f: From b8183ee98fcc55e74a8cd5b3b1fa6b4cba628fa1 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Wed, 22 Feb 2023 10:11:12 +0100 Subject: [PATCH 08/16] Do not check "junit-results.xml" As I use `parametrize` here "bad" words going into the function names of our test suite and from there into the results file. Ignore this file as it is correct to have these bad names in there. Actually we expect codespell to tell us about these bad names. --- .github/workflows/codespell-private.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 0053221df8..22211da492 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -54,7 +54,7 @@ jobs: # tomli should not be required for the next two steps (and make sure it's not) - run: pip uninstall -yq tomli if: ${{ matrix.no-toml == 'no-toml' }} - - run: codespell --check-filenames --skip="./.git/*,./.pytest_cache/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" + - run: codespell --check-filenames --skip="./.git/*,./.pytest_cache/*,./junit-results.xml,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" # this file has an error - run: "! codespell codespell_lib/tests/test_basic.py" From c5a6f5be68f97ec251305542bf68b3fc72615dfc Mon Sep 17 00:00:00 2001 From: herr kaste Date: Wed, 22 Feb 2023 10:14:27 +0100 Subject: [PATCH 09/16] Blacken Apparantely I had a local style override. So "black" again. --- codespell_lib/tests/test_basic.py | 48 +++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 46308207a0..1c0b79d5e1 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -392,48 +392,48 @@ def test_ignore_word_list( @pytest.mark.parametrize( - 'content, expected_error_count', + "content, expected_error_count", [ # recommended form - ('abandonned abondon abilty # codespell:ignore abondon', 2), - ('abandonned abondon abilty // codespell:ignore abondon,abilty', 1), + ("abandonned abondon abilty # codespell:ignore abondon", 2), + ("abandonned abondon abilty // codespell:ignore abondon,abilty", 1), ( - 'abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty', + "abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty", 0, ), # noqa: E501 # ignore unused ignore - ('abandonned abondon abilty # codespell:ignore nomenklatur', 3), + ("abandonned abondon abilty # codespell:ignore nomenklatur", 3), # wildcard form - ('abandonned abondon abilty # codespell:ignore ', 0), - ('abandonned abondon abilty # codespell:ignore', 0), - ('abandonned abondon abilty # codespell:ignore\n', 0), - ('abandonned abondon abilty # codespell:ignore\r\n', 0), - ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore # noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore# noqa: E501\n', 0), - ('abandonned abondon abilty # codespell:ignore, noqa: E501\n', 0), - ('abandonned abondon abilty #codespell:ignore\n', 0), + ("abandonned abondon abilty # codespell:ignore ", 0), + ("abandonned abondon abilty # codespell:ignore", 0), + ("abandonned abondon abilty # codespell:ignore\n", 0), + ("abandonned abondon abilty # codespell:ignore\r\n", 0), + ("abandonned abondon abilty # codespell:ignore # noqa: E501\n", 0), + ("abandonned abondon abilty # codespell:ignore # noqa: E501\n", 0), + ("abandonned abondon abilty # codespell:ignore# noqa: E501\n", 0), + ("abandonned abondon abilty # codespell:ignore, noqa: E501\n", 0), + ("abandonned abondon abilty #codespell:ignore\n", 0), # ignore these for safety - ('abandonned abondon abilty # codespell:ignorenoqa: E501\n', 3), - ('abandonned abondon abilty codespell:ignore\n', 3), - ('abandonned abondon abilty codespell:ignore\n', 3), + ("abandonned abondon abilty # codespell:ignorenoqa: E501\n", 3), + ("abandonned abondon abilty codespell:ignore\n", 3), + ("abandonned abondon abilty codespell:ignore\n", 3), # showcase different comment markers ("abandonned abondon abilty ' codespell:ignore\n", 0), ('abandonned abondon abilty " codespell:ignore\n', 0), - ('abandonned abondon abilty ;; codespell:ignore\n', 0), - ('abandonned abondon abilty /* codespell:ignore */\n', 0), + ("abandonned abondon abilty ;; codespell:ignore\n", 0), + ("abandonned abondon abilty /* codespell:ignore */\n", 0), # prose examples ( - 'You could also use line based igore ( codespell:ignore ) to igore ', + "You could also use line based igore ( codespell:ignore ) to igore ", 0, ), - ('You could also use line based igore (codespell:ignore) to igore ', 0), + ("You could also use line based igore (codespell:ignore) to igore ", 0), ( - 'You could also use line based igore (codespell:ignore igore) to igore ', + "You could also use line based igore (codespell:ignore igore) to igore ", 0, ), # noqa: E501 ( - 'You could also use line based igore (codespell:ignore igare) to igore ', + "You could also use line based igore (codespell:ignore igare) to igore ", 2, ), # noqa: E501 ], @@ -445,7 +445,7 @@ def test_inline_ignores( expected_error_count: int, ) -> None: d = str(tmpdir) - with open(op.join(d, 'bad.txt'), 'w') as f: + with open(op.join(d, "bad.txt"), "w") as f: f.write(content) assert cs.main(d) == expected_error_count From de6ddbbb79ba9508d9c53ebcd3f82cdc15517744 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Thu, 8 Feb 2024 19:21:31 +0100 Subject: [PATCH 10/16] Fix ruff error but one --- codespell_lib/tests/test_basic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 1c0b79d5e1..a5be0c6e07 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -392,7 +392,7 @@ def test_ignore_word_list( @pytest.mark.parametrize( - "content, expected_error_count", + ("content", "expected_error_count"), [ # recommended form ("abandonned abondon abilty # codespell:ignore abondon", 2), @@ -400,7 +400,7 @@ def test_ignore_word_list( ( "abandonned abondon abilty /* codespell:ignore abandonned,abondon,abilty", 0, - ), # noqa: E501 + ), # ignore unused ignore ("abandonned abondon abilty # codespell:ignore nomenklatur", 3), # wildcard form @@ -431,11 +431,11 @@ def test_ignore_word_list( ( "You could also use line based igore (codespell:ignore igore) to igore ", 0, - ), # noqa: E501 + ), ( "You could also use line based igore (codespell:ignore igare) to igore ", 2, - ), # noqa: E501 + ), ], ) def test_inline_ignores( From 94624c666b2eec9ed8a7872b4b433a8d2cb5b04e Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 9 Feb 2024 10:54:16 +0100 Subject: [PATCH 11/16] Increase PLR0915 sensitivity --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 9676de199f..aaf103fa8c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -171,4 +171,4 @@ allow-magic-value-types = ["bytes", "int", "str",] max-args = 13 max-branches = 49 max-returns = 11 -max-statements = 113 +max-statements = 200 From 9450f96c2dc59ac4bc0f86801e2dae642e45ed7d Mon Sep 17 00:00:00 2001 From: herr kaste Date: Fri, 9 Feb 2024 18:25:30 +0100 Subject: [PATCH 12/16] Ensure per test that `codespell:igore` is not a valid marker ... because ignore is spelled "igore". Co-authored-by: Peter Newman --- codespell_lib/tests/test_basic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index a5be0c6e07..24cf870068 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -417,6 +417,8 @@ def test_ignore_word_list( ("abandonned abondon abilty # codespell:ignorenoqa: E501\n", 3), ("abandonned abondon abilty codespell:ignore\n", 3), ("abandonned abondon abilty codespell:ignore\n", 3), + # ignore these as they aren't valid + ("abandonned abondon abilty # codespell:igore\n", 3), # showcase different comment markers ("abandonned abondon abilty ' codespell:ignore\n", 0), ('abandonned abondon abilty " codespell:ignore\n', 0), From c07e6a898d3afa167695059c3caa414547d4b980 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 10 Feb 2024 02:01:28 +0100 Subject: [PATCH 13/16] Of course "igore" itself is misspelled so the error count is 4 --- codespell_lib/tests/test_basic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 24cf870068..645bb49583 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -418,7 +418,7 @@ def test_ignore_word_list( ("abandonned abondon abilty codespell:ignore\n", 3), ("abandonned abondon abilty codespell:ignore\n", 3), # ignore these as they aren't valid - ("abandonned abondon abilty # codespell:igore\n", 3), + ("abandonned abondon abilty # codespell:igore\n", 4), # showcase different comment markers ("abandonned abondon abilty ' codespell:ignore\n", 0), ('abandonned abondon abilty " codespell:ignore\n', 0), From 4095d7cb5fa96ccbe182d517b6ff17867e446a22 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 10 Feb 2024 14:07:09 +0100 Subject: [PATCH 14/16] Revert changes to the GitHub action as requested --- .github/workflows/codespell-private.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 22211da492..9e37ad1ca3 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -54,7 +54,7 @@ jobs: # tomli should not be required for the next two steps (and make sure it's not) - run: pip uninstall -yq tomli if: ${{ matrix.no-toml == 'no-toml' }} - - run: codespell --check-filenames --skip="./.git/*,./.pytest_cache/*,./junit-results.xml,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" + - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" # this file has an error - run: "! codespell codespell_lib/tests/test_basic.py" From 3ccd651d27a8c72c86e9b45424855385078885b2 Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 10 Feb 2024 14:09:49 +0100 Subject: [PATCH 15/16] Allow exactly 119 statements as requested --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index aaf103fa8c..70aa216f06 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -171,4 +171,4 @@ allow-magic-value-types = ["bytes", "int", "str",] max-args = 13 max-branches = 49 max-returns = 11 -max-statements = 200 +max-statements = 119 From f2feecaac73df94e52839b2e6018fb87ef6c705f Mon Sep 17 00:00:00 2001 From: herr kaste Date: Sat, 10 Feb 2024 19:57:16 +0100 Subject: [PATCH 16/16] Revert "Revert changes to the GitHub action as requested" This reverts commit 4095d7cb5fa96ccbe182d517b6ff17867e446a22. --- .github/workflows/codespell-private.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index 9e37ad1ca3..22211da492 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -54,7 +54,7 @@ jobs: # tomli should not be required for the next two steps (and make sure it's not) - run: pip uninstall -yq tomli if: ${{ matrix.no-toml == 'no-toml' }} - - run: codespell --check-filenames --skip="./.git/*,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" + - run: codespell --check-filenames --skip="./.git/*,./.pytest_cache/*,./junit-results.xml,*.pyc,./codespell_lib/tests/test_basic.py,./codespell_lib/data/*,./example/code.c,./build/lib/codespell_lib/tests/test_basic.py,./build/lib/codespell_lib/data/*,README.rst,*.egg-info/*,pyproject-codespell.precommit-toml,./.mypy_cache" # this file has an error - run: "! codespell codespell_lib/tests/test_basic.py"