Skip to content

Commit 5c7e58d

Browse files
authored
Update check_heading_case.py
1 parent eec944d commit 5c7e58d

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

check_heading_case.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
import argparse
2+
import os
23
import re
34
import sys
45
from pathlib import Path
56

7+
IN_GITHUB_ACTIONS = os.environ.get("GITHUB_ACTIONS") == "true"
8+
9+
10+
def emit(path, line, message):
11+
print(f"{path}:{line}: {message}")
12+
if IN_GITHUB_ACTIONS:
13+
print(f"::error file={path},line={line}::{message}")
14+
615
SMALL_WORDS = {
716
"a", "an", "the",
817
"and", "or", "but", "nor", "so", "yet",
@@ -17,12 +26,13 @@
1726
INLINE_CODE_RE = re.compile(r"`[^`]*`")
1827

1928

29+
TOKEN_RE = re.compile(r"[A-Za-z0-9'’]+|[^A-Za-z0-9'’]+")
30+
31+
2032
def split_words_preserving_delims(text):
2133
tokens = []
22-
for part in re.split(r"(\s+|-)", text):
23-
if part == "":
24-
continue
25-
is_word = bool(re.match(r"^[A-Za-z][A-Za-z0-9'’]*$", part))
34+
for part in TOKEN_RE.findall(text):
35+
is_word = part[0].isalpha()
2636
tokens.append((part, is_word))
2737
return tokens
2838

@@ -139,8 +149,8 @@ def main():
139149
issues = process_file(path, fix=args.fix)
140150
for lineno, hashes, raw_text, suggestion in issues:
141151
total_issues += 1
142-
print(f"{path}:{lineno + 1}: {hashes} {raw_text}")
143-
print(f" suggestion -> {hashes} {suggestion}")
152+
message = f"Heading case: '{hashes} {raw_text}' should be '{hashes} {suggestion}'"
153+
emit(str(path), lineno + 1, message)
144154

145155
if total_issues == 0:
146156
print("All headings pass title case check.")

0 commit comments

Comments
 (0)