From 61a9973b13912640c9c6fe9caa035c1827f1186d Mon Sep 17 00:00:00 2001 From: Nytelife26 Date: Mon, 17 May 2021 03:31:10 +0100 Subject: [PATCH 1/3] fix: reduce false positives in uncomparables --- proselint/checks/uncomparables/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proselint/checks/uncomparables/misc.py b/proselint/checks/uncomparables/misc.py index 26d17b37f..2045c8f31 100644 --- a/proselint/checks/uncomparables/misc.py +++ b/proselint/checks/uncomparables/misc.py @@ -114,7 +114,7 @@ def check(text): ("more", "possible") # FIXME ] - all = [i[0] + r"\s" + i[1] + r"[\W$]" for i in itertools.product( + all = [fr"(^|\W){i[0]}\s{i[1]}[\W$]" for i in itertools.product( comparators, uncomparables) if i not in exceptions] occ = re.finditer("|".join(all), text.lower()) From 6d8c5d9e36309d5783235b98496e0557fa3d43d7 Mon Sep 17 00:00:00 2001 From: Nytelife26 Date: Mon, 17 May 2021 11:12:06 +0100 Subject: [PATCH 2/3] test: use comprehensive testing for uncomparables --- tests/test_dfw_uncomparables.py | 28 ---------------------------- tests/test_uncomparables.py | 18 +++++++++++++++--- 2 files changed, 15 insertions(+), 31 deletions(-) delete mode 100644 tests/test_dfw_uncomparables.py diff --git a/tests/test_dfw_uncomparables.py b/tests/test_dfw_uncomparables.py deleted file mode 100644 index c395f8483..000000000 --- a/tests/test_dfw_uncomparables.py +++ /dev/null @@ -1,28 +0,0 @@ -"""Test dfw.uncomparables.""" -from __future__ import absolute_import - -from .check import Check -from proselint.checks.uncomparables import misc as chk - - -class TestCheck(Check): - """The test class for dfw.uncomparables.""" - - __test__ = True - - @property - def this_check(self): - """Boilerplate.""" - return chk - - def test_sample_phrases(self): - """Find 'very unique'.""" - assert not self.passes("""This sentence is very unique.""") - - def test_linebreaks(self): - """Handle linebreaks correctly.""" - assert not self.passes("""This sentence is very\nunique.""") - - def test_constitutional(self): - """Don't flag 'more perfect'.""" - assert self.passes("""A more perfect union.""") diff --git a/tests/test_uncomparables.py b/tests/test_uncomparables.py index d8f3ddccc..bb1dd03b6 100644 --- a/tests/test_uncomparables.py +++ b/tests/test_uncomparables.py @@ -1,8 +1,6 @@ -"""Tests for uncomparables.misc check.""" +"""Test uncomparables.misc""" from __future__ import absolute_import - from .check import Check - from proselint.checks.uncomparables import misc as chk @@ -20,3 +18,17 @@ def test_smoke(self): """Basic smoke test for uncomparables.misc.""" assert self.passes("""Smoke phrase with nothing flagged.""") assert not self.passes("""The item was more unique.""") + + def test_sample_phrases(self): + """Find 'very unique'.""" + assert not self.passes("""This sentence is very unique.""") + + def test_spaces(self): + """Handle spacing correctly.""" + assert not self.passes("""This sentence is very\nunique.""") + assert not self.passes("""Kind of complete.""") + assert self.passes("""Every perfect instance.""") + + def test_constitutional(self): + """Don't flag exceptions.""" + assert self.passes("""A more perfect union.""") From 0745774240f08ad1f4a67e241960b4f860c40c0a Mon Sep 17 00:00:00 2001 From: Nytelife26 Date: Mon, 17 May 2021 11:51:06 +0100 Subject: [PATCH 3/3] refactor: use existence_check for uncomparables --- proselint/checks/uncomparables/misc.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/proselint/checks/uncomparables/misc.py b/proselint/checks/uncomparables/misc.py index 2045c8f31..4dce6aabf 100644 --- a/proselint/checks/uncomparables/misc.py +++ b/proselint/checks/uncomparables/misc.py @@ -45,7 +45,7 @@ attention and expects you to have done the same. """ import re -from proselint.tools import memoize +from proselint.tools import existence_check, memoize import itertools @@ -114,9 +114,7 @@ def check(text): ("more", "possible") # FIXME ] - all = [fr"(^|\W){i[0]}\s{i[1]}[\W$]" for i in itertools.product( - comparators, uncomparables) if i not in exceptions] + uncomparables = [fr"{i[0]}\s{i[1]}" for i in itertools.product( + comparators, uncomparables) if i not in exceptions] - occ = re.finditer("|".join(all), text.lower()) - return [(o.start(), o.end(), err, msg.format(o.group(0)), None) - for o in occ] + return existence_check(text, uncomparables, err, msg, require_padding=True)