Skip to content

Commit 258b0b3

Browse files
authored
Refactor Harper CI workflow and linting logic
1 parent d429fe7 commit 258b0b3

1 file changed

Lines changed: 26 additions & 13 deletions

File tree

.github/workflows/harper.yml

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ jobs:
2020
~/.cargo/bin
2121
~/.cargo/registry
2222
~/.cargo/git
23-
target
24-
key: ${{ runner.os }}-cargo-harper-${{ hashFiles('.github/workflows/harper.yml') }}
23+
key: ${{ runner.os }}-cargo-harper
2524
restore-keys: |
26-
${{ runner.os }}-cargo-harper-
25+
${{ runner.os }}-cargo-harper
2726
2827
- name: Install Harper CLI
2928
run: |
@@ -53,10 +52,12 @@ jobs:
5352
5453
for report in reports:
5554
for lint in report.get("lints", []):
56-
if lint.get("kind") == "Spelling":
57-
word = lint.get("matched_text")
58-
if word:
59-
words.add(word)
55+
kind = lint.get("kind")
56+
rule = lint.get("rule")
57+
word = lint.get("matched_text")
58+
59+
if kind == "Spelling" and rule == "SpellCheck" and word:
60+
words.add(word)
6061
6162
print("Suggested dictionary candidates:")
6263
for word in sorted(words, key=str.lower):
@@ -73,23 +74,35 @@ jobs:
7374
reports = json.load(f)
7475
7576
selected = []
77+
total_lints = 0
78+
79+
IGNORED_RULES = {
80+
("Spelling", "OkToOkay"),
81+
("Spelling", "DisjointPrefixes"),
82+
}
7683
7784
for report in reports:
7885
file = report.get("file")
7986
8087
for lint in report.get("lints", []):
88+
total_lints += 1
89+
8190
kind = lint.get("kind")
8291
rule = lint.get("rule")
8392
line_no = lint.get("line")
8493
message = lint.get("message")
8594
text = lint.get("matched_text")
8695
87-
if kind == "Spelling" and rule == "SpellCheck":
88-
keep = True
89-
if kind == "Grammar":
90-
keep = True
91-
if kind == "Repetition":
92-
keep = True
96+
if (kind, rule) in IGNORED_RULES:
97+
continue
98+
99+
if kind in {"Spelling", "Grammar", "Repetition"}:
100+
selected.append(
101+
f"{file}:{line_no}: [{kind}::{rule}] {text!r} - {message}"
102+
)
103+
104+
print(f"Total Harper lint count: {total_lints}")
105+
print(f"Selected lint count: {len(selected)}")
93106
94107
if selected:
95108
print("Selected Harper lints found:")

0 commit comments

Comments
 (0)