Skip to content

Commit f9d0e3c

Browse files
authored
Enhance Harper rule check with ignore conditions
Added a function to ignore certain spelling texts based on specific criteria.
1 parent 258b0b3 commit f9d0e3c

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

.github/workflows/harper.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ jobs:
6868
run: |
6969
python - <<'PY'
7070
import json
71+
import re
7172
import sys
7273
7374
with open("harper-report.json", encoding="utf-8") as f:
@@ -81,6 +82,34 @@ jobs:
8182
("Spelling", "DisjointPrefixes"),
8283
}
8384
85+
def should_ignore_spelling_text(text):
86+
if not text:
87+
return False
88+
89+
stripped = text.strip()
90+
91+
# URLs and URL fragments
92+
if stripped.startswith(("http://", "https://", "www.")):
93+
return True
94+
95+
# File paths / command paths
96+
if "/" in stripped:
97+
return True
98+
99+
# Long hashes, IDs, tokens
100+
if len(stripped) >= 16 and any(c.isdigit() for c in stripped):
101+
return True
102+
103+
# Hex-like strings, e.g. d5442a5dc4baadd48b32
104+
if len(stripped) >= 8 and re.fullmatch(r"[a-fA-F0-9]+", stripped):
105+
return True
106+
107+
# Mostly random-looking alphanumeric tokens
108+
if len(stripped) >= 12 and re.fullmatch(r"[A-Za-z0-9_-]+", stripped):
109+
return True
110+
111+
return False
112+
84113
for report in reports:
85114
file = report.get("file")
86115
@@ -96,6 +125,9 @@ jobs:
96125
if (kind, rule) in IGNORED_RULES:
97126
continue
98127
128+
if kind == "Spelling" and should_ignore_spelling_text(text):
129+
continue
130+
99131
if kind in {"Spelling", "Grammar", "Repetition"}:
100132
selected.append(
101133
f"{file}:{line_no}: [{kind}::{rule}] {text!r} - {message}"

0 commit comments

Comments
 (0)