-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmarkdown.py
More file actions
88 lines (73 loc) · 3.88 KB
/
markdown.py
File metadata and controls
88 lines (73 loc) · 3.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
"""
reporter/markdown.py
Renders a full Markdown modernisation report from analysis results.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from parser.structure import CobolProgram
from parser.antipatterns import Finding
from parser.complexity import ComplexityScore
_SEVERITY_EMOJI = {'HIGH': '🔴', 'MEDIUM': '🟡', 'LOW': '🟢'}
def render(
prog: "CobolProgram",
findings: list["Finding"],
scores: list["ComplexityScore"],
source_path: str,
annotations: dict[str, str] | None = None,
) -> str:
lines: list[str] = []
lines.append(f"# COBOL Modernisation Report")
lines.append(f"\n**File:** `{source_path}` ")
lines.append(f"**Program ID:** `{prog.program_id}` ")
lines.append(f"**Total lines:** {len(prog.raw_lines)} ")
lines.append(f"**Data items:** {len(prog.data_items)} ")
lines.append(f"**Paragraphs:** {len(prog.paragraphs)} ")
# ── Summary ──────────────────────────────────────────────────────────────
high = sum(1 for f in findings if f.severity == 'HIGH')
medium = sum(1 for f in findings if f.severity == 'MEDIUM')
low = sum(1 for f in findings if f.severity == 'LOW')
lines.append("\n---\n")
lines.append("## Summary\n")
lines.append(f"| Severity | Count |")
lines.append(f"|----------|-------|")
lines.append(f"| 🔴 High | {high} |")
lines.append(f"| 🟡 Medium | {medium} |")
lines.append(f"| 🟢 Low | {low} |")
# ── Anti-patterns ─────────────────────────────────────────────────────────
lines.append("\n---\n")
lines.append("## Anti-patterns Detected\n")
if not findings:
lines.append("✅ No anti-patterns detected.")
else:
for f in findings:
emoji = _SEVERITY_EMOJI.get(f.severity, '')
lines.append(f"### {emoji} `{f.category}` — Line {f.line}")
lines.append(f"\n{f.description}\n")
if f.snippet:
lines.append(f"```cobol\n{f.snippet}\n```\n")
# ── Complexity ────────────────────────────────────────────────────────────
lines.append("\n---\n")
lines.append("## Paragraph Complexity (Top 10)\n")
lines.append("| Rank | Paragraph | Complexity | Line |")
lines.append("|------|-----------|------------|------|")
for i, s in enumerate(scores[:10], 1):
flag = " ⚠️" if s.score >= 10 else ""
lines.append(f"| {i} | `{s.paragraph}` | {s.score}{flag} | {s.line} |")
# ── Data inventory ────────────────────────────────────────────────────────
lines.append("\n---\n")
lines.append("## Working-Storage Data Items\n")
lines.append("| Level | Name | PIC | Value |")
lines.append("|-------|------|-----|-------|")
for d in prog.data_items:
lines.append(f"| {d.level:02d} | `{d.name}` | `{d.pic or '-'}` | `{d.value or '-'}` |")
# ── Paragraph annotations ─────────────────────────────────────────────────
if annotations:
lines.append("\n---\n")
lines.append("## Paragraph Annotations\n")
for para_name, summary in annotations.items():
lines.append(f"### `{para_name}`\n")
lines.append(f"{summary}\n")
lines.append("\n---\n")
lines.append("*Generated by [cobol-moderniser](https://github.com/Atri2-code/cobol-moderniser)*")
return '\n'.join(lines)