Skip to content

Commit e1e57f9

Browse files
committed
fix: πŸ› Fix markdown formatting
1 parent 48656f2 commit e1e57f9

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

β€Žcodelimit/commands/report.pyβ€Ž

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import typer
55
from rich import print
66
from rich.console import Console
7+
from rich.text import Text
78

89
from codelimit.common.ScanResultTable import ScanResultTable
910
from codelimit.common.ScanTotals import ScanTotals
@@ -22,15 +23,16 @@ class ReportFormat(str, Enum):
2223

2324

2425
def report_command(path: Path, full: bool, totals: bool, fmt: ReportFormat):
26+
stdout = Console()
2527
report = read_report(path)
2628
if totals:
2729
scan_totals = ScanTotals(report.codebase.totals)
2830
if fmt == ReportFormat.markdown:
29-
print(_report_totals_markdown(scan_totals))
31+
stdout.print(_report_totals_markdown(scan_totals), soft_wrap=True)
3032
else:
31-
print(ScanResultTable(scan_totals))
33+
stdout.print(ScanResultTable(scan_totals), soft_wrap=True)
3234
else:
33-
_report_units(report, path, full, fmt)
35+
_report_functions(report, path, full, fmt, stdout)
3436

3537

3638
def _report_totals_markdown(st: ScanTotals) -> str:
@@ -60,10 +62,10 @@ def _report_totals_markdown(st: ScanTotals) -> str:
6062
return result
6163

6264

63-
def _report_units(report: Report, path: Path, full: bool, fmt):
65+
def _report_functions(report: Report, path: Path, full: bool, fmt, console: Console):
6466
units = report.all_report_units_sorted_by_length_asc(30)
6567
if len(units) == 0:
66-
print(
68+
console.print(
6769
"[bold]Refactoring not necessary, :sparkles: happy coding! :sparkles:[/bold]"
6870
)
6971
return
@@ -73,9 +75,9 @@ def _report_units(report: Report, path: Path, full: bool, fmt):
7375
report_units = units[0:REPORT_LENGTH]
7476
root = get_root(path)
7577
if fmt == ReportFormat.markdown:
76-
print(_print_functions_markdown(root, report_units))
78+
console.print(_report_functions_markdown(root, report_units), soft_wrap=True)
7779
else:
78-
_print_functions_text(root, units, report_units, full)
80+
console.print(_report_functions_text(root, units, report_units, full), soft_wrap=True)
7981

8082

8183
def get_root(path: Path) -> Path | None:
@@ -101,20 +103,17 @@ def read_report(path: Path) -> Report:
101103
return ReportReader.from_json(report_data)
102104

103105

104-
def _print_functions_text(root, units, report_units, full):
105-
stdout = Console()
106+
def _report_functions_text(root, units, report_units, full) -> Text:
107+
result = Text()
106108
for unit in report_units:
107109
file_path = unit.file if root is None else root.joinpath(unit.file)
108-
stdout.print(
109-
format_measurement(str(file_path), unit.measurement), soft_wrap=True
110-
)
110+
result.append(format_measurement(str(file_path), unit.measurement).append("\n"))
111111
if not full and len(units) > REPORT_LENGTH:
112-
print(
113-
f"[bold]{len(units) - REPORT_LENGTH} more rows, use --full option to get all rows[/bold]"
114-
)
112+
result.append(f"[bold]{len(units) - REPORT_LENGTH} more rows, use --full option to get all rows[/bold]\n")
113+
return result
115114

116115

117-
def _print_functions_markdown(root: Path | None, report_units: list[ReportUnit]) -> str:
116+
def _report_functions_markdown(root: Path | None, report_units: list[ReportUnit]) -> str:
118117
result = ""
119118
result += "| **File** | **Line** | **Column** | **Length** | **Function** |\n"
120119
result += "| --- | ---: | ---: | ---: | --- |\n"

β€Žtests/commands/test_report.pyβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from codelimit.commands.report import _report_totals_markdown, _print_functions_markdown
1+
from codelimit.commands.report import _report_totals_markdown, _report_functions_markdown
22
from codelimit.common.LanguageTotals import LanguageTotals
33
from codelimit.common.Location import Location
44
from codelimit.common.Measurement import Measurement
@@ -49,7 +49,7 @@ def test_report_totals_markdown_two_languages():
4949

5050

5151
def test_print_functions_markdown():
52-
result = _print_functions_markdown(
52+
result = _report_functions_markdown(
5353
None,
5454
[
5555
ReportUnit(

0 commit comments

Comments
Β (0)