Skip to content

Commit 95faedd

Browse files
linting: create linting check
1 parent f62bd3c commit 95faedd

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
run: |
2424
bash ./_tools/check-rst.sh
2525
26+
- name: Custom RST checks (check_rst_headings.py)
27+
run: python3 _tools/check_rst_headings.py
28+
2629
- name: Get Python version
2730
id: pythonv
2831
run: |

_tools/check_rst_headings.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import re
3+
import sys
4+
5+
def check_headings():
6+
search_dir = "tutorials"
7+
exclude_path = "tutorials/io/binary_serialization_api.rst"
8+
info_message = "Headings which start with a number must have a custom anchor defined before them to prevent malformed link fragments. See here: https://docs.godotengine.org/en/stable/contributing/documentation/docs_writing_guidelines.html \n"
9+
10+
pattern = re.compile(r"^(?!\.\. _doc)(.+\n\s*^\d.*\n^[~-].*)", re.M)
11+
12+
found_issues = False
13+
header_printed = False
14+
15+
for root, _, files in os.walk(search_dir):
16+
for f in files:
17+
path = os.path.join(root, f)
18+
19+
if not f.endswith(".rst") or path == exclude_path:
20+
continue
21+
22+
with open(path, "r", encoding="utf-8") as file:
23+
content = file.read()
24+
25+
for match in pattern.finditer(content):
26+
if not header_printed:
27+
print(f"{info_message}\n")
28+
header_printed = True
29+
30+
line_no = content[:match.start()].count("\n") + 1
31+
print(f"Violation in {path} at line {line_no}:\n{match.group(1)}\n")
32+
found_issues = True
33+
34+
if found_issues:
35+
sys.exit(1)
36+
37+
if __name__ == "__main__":
38+
check_headings()

0 commit comments

Comments
 (0)