Skip to content

Commit b3f57dd

Browse files
committed
Fix developer guide lint parsing and Java setup
1 parent 922ac2b commit b3f57dd

File tree

3 files changed

+95
-25
lines changed

3 files changed

+95
-25
lines changed

.github/workflows/developer-guide-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ jobs:
8686
uses: actions/setup-java@v4
8787
with:
8888
distribution: temurin
89-
java-version: '21'
89+
java-version: '17'
9090

9191
- name: Install Asciidoctor tooling
9292
run: |

scripts/developer-guide/summarize_reports.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,52 @@
1010
from typing import Iterable
1111

1212

13+
def _is_alert(candidate: dict[str, object]) -> bool:
14+
required_keys = {"Severity", "Check", "Message"}
15+
return required_keys.issubset(candidate.keys())
16+
17+
18+
def _collect_alerts(node: object, path_hint: str = "") -> list[dict[str, object]]:
19+
alerts: list[dict[str, object]] = []
20+
21+
if isinstance(node, dict):
22+
if _is_alert(node):
23+
alert = dict(node)
24+
if path_hint and not alert.get("Path"):
25+
alert["Path"] = path_hint
26+
alerts.append(alert)
27+
return alerts
28+
29+
node_path = path_hint
30+
path_value = node.get("Path")
31+
if isinstance(path_value, str) and path_value:
32+
node_path = path_value
33+
34+
alert_list = node.get("alerts")
35+
if isinstance(alert_list, list):
36+
alerts.extend(_collect_alerts(alert_list, node_path))
37+
38+
file_map = node.get("files")
39+
if isinstance(file_map, dict):
40+
for file_path, file_node in file_map.items():
41+
hint = file_path if isinstance(file_path, str) else node_path
42+
alerts.extend(_collect_alerts(file_node, hint))
43+
44+
for key, value in node.items():
45+
if key in {"alerts", "files", "Path"}:
46+
continue
47+
hint = node_path
48+
if isinstance(key, str) and ("/" in key or key.endswith(".adoc") or key.endswith(".asciidoc")):
49+
hint = key
50+
alerts.extend(_collect_alerts(value, hint))
51+
52+
elif isinstance(node, list):
53+
for item in node:
54+
alerts.extend(_collect_alerts(item, path_hint))
55+
56+
return alerts
57+
58+
1359
def write_output(lines: Iterable[str], output: Path | None) -> None:
1460
content = "\n".join(lines) + "\n"
1561
if output:
@@ -56,17 +102,7 @@ def summarize_vale(
56102
data = json.loads(report.read_text(encoding="utf-8"))
57103
except json.JSONDecodeError:
58104
data = {}
59-
if isinstance(data, dict):
60-
if isinstance(data.get("alerts"), list):
61-
alerts.extend(data["alerts"])
62-
files = data.get("files")
63-
if isinstance(files, dict):
64-
for file_result in files.values():
65-
if not isinstance(file_result, dict):
66-
continue
67-
file_alerts = file_result.get("alerts")
68-
if isinstance(file_alerts, list):
69-
alerts.extend(file_alerts)
105+
alerts = _collect_alerts(data)
70106

71107
counts = {"error": 0, "warning": 0, "suggestion": 0}
72108
total = 0

scripts/developer-guide/vale_report_to_html.py

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,52 @@
1010
from typing import Iterable
1111

1212

13+
def _is_alert(candidate: dict[str, object]) -> bool:
14+
required_keys = {"Severity", "Check", "Message"}
15+
return required_keys.issubset(candidate.keys())
16+
17+
18+
def _collect_alerts(node: object, path_hint: str = "") -> list[dict[str, object]]:
19+
alerts: list[dict[str, object]] = []
20+
21+
if isinstance(node, dict):
22+
if _is_alert(node):
23+
alert = dict(node)
24+
if path_hint and not alert.get("Path"):
25+
alert["Path"] = path_hint
26+
alerts.append(alert)
27+
return alerts
28+
29+
node_path = path_hint
30+
path_value = node.get("Path")
31+
if isinstance(path_value, str) and path_value:
32+
node_path = path_value
33+
34+
alert_list = node.get("alerts")
35+
if isinstance(alert_list, list):
36+
alerts.extend(_collect_alerts(alert_list, node_path))
37+
38+
file_map = node.get("files")
39+
if isinstance(file_map, dict):
40+
for file_path, file_node in file_map.items():
41+
hint = file_path if isinstance(file_path, str) else node_path
42+
alerts.extend(_collect_alerts(file_node, hint))
43+
44+
for key, value in node.items():
45+
if key in {"alerts", "files", "Path"}:
46+
continue
47+
hint = node_path
48+
if isinstance(key, str) and ("/" in key or key.endswith(".adoc") or key.endswith(".asciidoc")):
49+
hint = key
50+
alerts.extend(_collect_alerts(value, hint))
51+
52+
elif isinstance(node, list):
53+
for item in node:
54+
alerts.extend(_collect_alerts(item, path_hint))
55+
56+
return alerts
57+
58+
1359
def parse_args() -> argparse.Namespace:
1460
parser = argparse.ArgumentParser(description=__doc__)
1561
parser.add_argument("--input", type=Path, required=True, help="Path to the Vale JSON report.")
@@ -25,19 +71,7 @@ def load_alerts(report: Path) -> list[dict[str, object]]:
2571
except json.JSONDecodeError:
2672
return []
2773

28-
alerts: list[dict[str, object]] = []
29-
if isinstance(data, dict):
30-
if isinstance(data.get("alerts"), list):
31-
alerts.extend(data["alerts"])
32-
files = data.get("files")
33-
if isinstance(files, dict):
34-
for file_result in files.values():
35-
if not isinstance(file_result, dict):
36-
continue
37-
file_alerts = file_result.get("alerts")
38-
if isinstance(file_alerts, list):
39-
alerts.extend(file_alerts)
40-
return alerts
74+
return _collect_alerts(data)
4175

4276

4377
def render_alert_rows(alerts: Iterable[dict[str, object]]) -> str:

0 commit comments

Comments
 (0)