From d05ea13968dee1941746b27681ab914c982e5e4a Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 01:15:08 +0100 Subject: [PATCH 1/8] Test to check our string escape word triggers on its own --- codespell_lib/tests/test_basic.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index b16a2d82b7..58e9aaef07 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -97,6 +97,9 @@ def test_basic( with fname.open("a") as f: f.write("this is a test file\n") assert cs.main(fname) == 0, "good" + with fname.open("a") as f: + f.write("var = 'nDoes not error on newline'\n") + assert cs.main(fname) == 1, "checking our string escape test word is bad" with fname.open("a") as f: f.write("var = '\\nDoes not error on newline'\n") assert cs.main(fname) == 0, "with string escape" From a2ae09c975a013a355d830c1891909dfe661a526 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 01:29:30 +0100 Subject: [PATCH 2/8] Change to some words which ought to actually trigger codespell --- codespell_lib/tests/test_basic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 58e9aaef07..15201177fa 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -98,10 +98,10 @@ def test_basic( f.write("this is a test file\n") assert cs.main(fname) == 0, "good" with fname.open("a") as f: - f.write("var = 'nDoes not error on newline'\n") - assert cs.main(fname) == 1, "checking our string escape test word is bad" + f.write("var = 'nwe must check codespell likes escapes nin strings'\n") + assert cs.main(fname) == 2, "checking our string escape test words are bad" with fname.open("a") as f: - f.write("var = '\\nDoes not error on newline'\n") + f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") assert cs.main(fname) == 0, "with string escape" with fname.open("a") as f: f.write("abandonned\n") From 46afe4acd1d49bef4513d5ce795974c112038a3a Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 01:41:39 +0100 Subject: [PATCH 3/8] Reorder tests so our counts of errors are correct --- codespell_lib/tests/test_basic.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 15201177fa..524718ef9f 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -97,12 +97,6 @@ def test_basic( with fname.open("a") as f: f.write("this is a test file\n") assert cs.main(fname) == 0, "good" - with fname.open("a") as f: - f.write("var = 'nwe must check codespell likes escapes nin strings'\n") - assert cs.main(fname) == 2, "checking our string escape test words are bad" - with fname.open("a") as f: - f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") - assert cs.main(fname) == 0, "with string escape" with fname.open("a") as f: f.write("abandonned\n") assert cs.main(fname) == 1, "bad" @@ -113,6 +107,12 @@ def test_basic( f.write("tim\ngonna\n") assert cs.main(fname) == 2, "with a name" assert cs.main("--builtin", "clear,rare,names,informal", fname) == 4 + with fname.open("w") as f: # overwrite the file + f.write("var = 'nwe must check codespell likes escapes nin strings'\n") + assert cs.main(fname) == 2, "checking our string escape test words are bad" + with fname.open("w") as f: # overwrite the file + f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") + assert cs.main(fname) == 0, "with string escape" result = cs.main(fname, "--builtin", "foo", std=True) assert isinstance(result, tuple) code, _, stderr = result From 07f902320fc8b0c4caf779289656bb4f5ef11194 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 01:48:20 +0100 Subject: [PATCH 4/8] Fix our error count and explain why --- codespell_lib/tests/test_basic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 524718ef9f..ba7a9fc702 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -109,7 +109,8 @@ def test_basic( assert cs.main("--builtin", "clear,rare,names,informal", fname) == 4 with fname.open("w") as f: # overwrite the file f.write("var = 'nwe must check codespell likes escapes nin strings'\n") - assert cs.main(fname) == 2, "checking our string escape test words are bad" + assert cs.main(fname) == 1, "checking our string escape test word is bad" + # the first one is missed because the apostrophe means its not currently treated as a word on its own with fname.open("w") as f: # overwrite the file f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") assert cs.main(fname) == 0, "with string escape" From c94df74d2a3787f410ec6544ef35431bc5fc328f Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 01:53:35 +0100 Subject: [PATCH 5/8] Add a note about backslash escapes to the readme --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 457094ee63..df90210562 100644 --- a/README.rst +++ b/README.rst @@ -2,7 +2,7 @@ codespell ========= Fix common misspellings in text files. It's designed primarily for checking -misspelled words in source code, but it can be used with other files as well. +misspelled words in source code (backslash escapes are skipped), but it can be used with other files as well. It does not check for word membership in a complete dictionary, but instead looks for a set of common misspellings. Therefore it should catch errors like "adn", but it will not catch "adnasdfasdf". This also means it shouldn't From 3f8038193f387a2d18f160c98da8257121fa8a55 Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 02:11:51 +0100 Subject: [PATCH 6/8] Force GitHub format so ruff auto-annotates --- .github/workflows/codespell-private.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/codespell-private.yml b/.github/workflows/codespell-private.yml index f6cda80f5e..b0dd6b6e50 100644 --- a/.github/workflows/codespell-private.yml +++ b/.github/workflows/codespell-private.yml @@ -12,6 +12,7 @@ jobs: test: env: REQUIRE_ASPELL: true + RUFF_FORMAT: github # Make sure we're using the latest aspell dictionary runs-on: ubuntu-22.04 strategy: @@ -75,6 +76,8 @@ jobs: - run: make check-dictionaries ruff-annotation: + env: + RUFF_FORMAT: github runs-on: ubuntu-latest steps: - name: Setup python From 817cfa8a444b65a24d7699a855f67acbe8d5f80b Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 02:18:36 +0100 Subject: [PATCH 7/8] Fix a lint error --- codespell_lib/tests/test_basic.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index ba7a9fc702..9c35ce091d 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -110,7 +110,8 @@ def test_basic( with fname.open("w") as f: # overwrite the file f.write("var = 'nwe must check codespell likes escapes nin strings'\n") assert cs.main(fname) == 1, "checking our string escape test word is bad" - # the first one is missed because the apostrophe means its not currently treated as a word on its own + # the first one is missed because the apostrophe means its not currently + # treated as a word on its own with fname.open("w") as f: # overwrite the file f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") assert cs.main(fname) == 0, "with string escape" From ed909bf7809eafbfd068de4cf451a3bdb6cbb7ad Mon Sep 17 00:00:00 2001 From: Peter Newman Date: Thu, 15 Jun 2023 02:23:47 +0100 Subject: [PATCH 8/8] Test double escapes are skipped --- codespell_lib/tests/test_basic.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index 9c35ce091d..603c973222 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -115,6 +115,11 @@ def test_basic( with fname.open("w") as f: # overwrite the file f.write("var = '\\nwe must check codespell likes escapes \\nin strings'\n") assert cs.main(fname) == 0, "with string escape" + with fname.open("w") as f: # overwrite the file + f.write("var = '\\\\nwe must check codespell ignores double escapes \\\\nin strings'\n") + assert cs.main(fname) == 2, "with string escape" + # the four backslashes here become two on disk and one when output to a file, + # so these typos should be found result = cs.main(fname, "--builtin", "foo", std=True) assert isinstance(result, tuple) code, _, stderr = result