Skip to content

Commit f1894bc

Browse files
feat(registry): add strict padding for checks (amperser#1428)
Prevent false positives due to words glued together by hyphens and apostrophes - Add test cases for amperser#306 - Add a `STRICT_WORDS_IN_TEXT` that does not include hyphens or apostrophes - Fix the `misc.preferred_forms` check - Refactor the `lexical_illusions` check to use `STRICT_WORDS_IN_TEXT` --------- Signed-off-by: drainpixie <121581793+drainpixie@users.noreply.github.com> Co-authored-by: Tyler J Russell <xtylerjrx@gmail.com>
1 parent 68be196 commit f1894bc

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

proselint/checks/lexical_illusions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919

2020
check = Check(
2121
check_type=types.ExistenceSimple(
22-
pattern=Padding.WORDS_IN_TEXT.format(
23-
r"(?<!\\|\-)(\w+(?:\s+\w+){0,3})(\s+\1)+"
22+
pattern=Padding.STRICT_WORDS_IN_TEXT.format(
23+
r"(\w+(?:\s+\w+){0,3})(\s+\1)+"
2424
),
2525
exceptions=(r"^had had$", r"^that that$"),
2626
),

proselint/checks/misc/preferred_forms.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
check = Check(
2323
check_type=types.PreferredFormsSimple(
24+
padding=Padding.STRICT_WORDS_IN_TEXT,
2425
items={
2526
# Obsolete words
2627
"imprimature": "imprimatur",

proselint/registry/checks/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,17 @@ class Padding(str, Enum):
3535
"""
3636
NONWORDS_IN_TEXT = r"\B{}\B"
3737
"""Match any position that is not a word boundary around the pattern."""
38+
STRICT_WORDS_IN_TEXT = r"(?<![A-Za-z'-]){}(?![A-Za-z'-])"
39+
"""Lookaround-based `WORDS_IN_TEXT`, prohibiting hyphens and apostrophes."""
3840

3941
def to_offset_from(self, offset: tuple[int, int]) -> tuple[int, int]:
4042
"""Calculate new offset values based on the applied padding."""
41-
if self in {Padding.RAW, Padding.SAFE_JOIN, Padding.WORDS_IN_TEXT}:
43+
if self in {
44+
Padding.RAW,
45+
Padding.SAFE_JOIN,
46+
Padding.WORDS_IN_TEXT,
47+
Padding.STRICT_WORDS_IN_TEXT,
48+
}:
4249
return offset
4350
return (offset[0] + 1, max(offset[1] - 1, 0))
4451

tests/examples.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,14 @@
317317
"It was almost haloween.",
318318
"He is Chief Justice of the Supreme Court of the United States.",
319319
"Meantime, I had tea.",
320+
"He jumped off of the couch.",
320321
"In the meanwhile, something happened.",
321322
"She went to bed; meantime, I had tea.",
322323
),
323324
(
324325
"Smoke phrase with nothing flagged.",
325326
"Meanwhile, I had tea.",
327+
"A 4th order low-pass with a roll-off of 24 db/octave",
326328
"In the meantime, something happened.",
327329
"She went to bed; meanwhile, I had tea."
328330
),

0 commit comments

Comments
 (0)