Skip to content

Commit b386c2a

Browse files
committed
feat: add stricter padding for off-of check
1 parent 9c24e8c commit b386c2a

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

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+
"""WORDS_IN_TEXT but disallows matches with 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
@@ -315,12 +315,14 @@
315315
"It was almost haloween.",
316316
"He is Chief Justice of the Supreme Court of the United States.",
317317
"Meantime, I had tea.",
318+
"He jumped off of the couch.",
318319
"In the meanwhile, something happened.",
319320
"She went to bed; meantime, I had tea.",
320321
),
321322
(
322323
"Smoke phrase with nothing flagged.",
323324
"Meanwhile, I had tea.",
325+
"A 4th order low-pass with a roll-off of 24 db/octave",
324326
"In the meantime, something happened.",
325327
"She went to bed; meanwhile, I had tea."
326328
),

0 commit comments

Comments
 (0)