Skip to content

Commit 7199730

Browse files
feat: ✨ Improve report (#61)
1 parent 52d6959 commit 7199730

File tree

24 files changed

+4771
-4701
lines changed

24 files changed

+4771
-4701
lines changed

codelimit/__main__.py

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from typer.core import TyperGroup
99

1010
from codelimit.commands.check import check_command
11-
from codelimit.commands.report.report import ReportFormat, report_command
11+
from codelimit.commands.findings import findings_command
12+
from codelimit.commands.report import ReportFormat, report_command
1213
from codelimit.commands.scan import scan_command
1314
from codelimit.common.Configuration import Configuration
1415
from codelimit.common.utils import configure_github_repository
@@ -27,22 +28,6 @@ def list_commands(self, ctx: Context):
2728
# cli.add_typer(app.app, name="app", help="Code Limit GitHub App commands")
2829

2930

30-
@cli.command(help="Check file(s)")
31-
def check(
32-
paths: Annotated[List[Path], typer.Argument(exists=True)],
33-
exclude: Annotated[
34-
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
35-
] = None,
36-
quiet: Annotated[
37-
bool, typer.Option("--quiet", help="No output when successful")
38-
] = False,
39-
):
40-
if exclude:
41-
Configuration.exclude.extend(exclude)
42-
Configuration.load(Path('.'))
43-
check_command(paths, quiet)
44-
45-
4631
@cli.command(help="Scan a codebase")
4732
def scan(
4833
path: Annotated[
@@ -64,14 +49,42 @@ def report(
6449
path: Annotated[
6550
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
6651
] = Path("."),
67-
full: Annotated[bool, typer.Option("--full", help="Show full report")] = False,
68-
totals: Annotated[bool, typer.Option("--totals", help="Only show totals")] = False,
6952
fmt: Annotated[
7053
ReportFormat, typer.Option("--format", help="Output format")
7154
] = ReportFormat.text,
7255
):
7356
Configuration.load(path)
74-
report_command(path, full, totals, fmt)
57+
report_command(path, fmt)
58+
59+
60+
@cli.command(help="Show findings for codebase")
61+
def findings(
62+
path: Annotated[
63+
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
64+
] = Path("."),
65+
full: Annotated[bool, typer.Option("--full", help="Show full findings")] = False,
66+
fmt: Annotated[
67+
ReportFormat, typer.Option("--format", help="Output format")
68+
] = ReportFormat.text,
69+
):
70+
Configuration.load(path)
71+
findings_command(path, full, fmt)
72+
73+
74+
@cli.command(help="Check file(s)")
75+
def check(
76+
paths: Annotated[List[Path], typer.Argument(exists=True)],
77+
exclude: Annotated[
78+
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
79+
] = None,
80+
quiet: Annotated[
81+
bool, typer.Option("--quiet", help="No output when successful")
82+
] = False,
83+
):
84+
if exclude:
85+
Configuration.exclude.extend(exclude)
86+
Configuration.load(Path('.'))
87+
check_command(paths, quiet)
7588

7689

7790
@cli.command(help="Generate badge Markdown")

codelimit/commands/findings.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pathlib import Path
2+
3+
from rich.console import Console
4+
5+
from codelimit.commands.report import ReportFormat
6+
from codelimit.common.report import format_markdown, format_text
7+
from codelimit.utils import read_report
8+
9+
10+
def findings_command(path: Path, full: bool, fmt: ReportFormat):
11+
stdout = Console(soft_wrap=True)
12+
report = read_report(path, stdout)
13+
if fmt == ReportFormat.markdown:
14+
format_markdown.print_findings(report, stdout, full)
15+
else:
16+
format_text.print_findings(report, stdout, full)

codelimit/commands/report.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pathlib import Path
2+
3+
from rich.console import Console
4+
5+
from codelimit.common.report import format_markdown, format_text
6+
from codelimit.common.report.ReportFormat import ReportFormat
7+
from codelimit.utils import read_report
8+
9+
10+
def report_command(path: Path, fmt: ReportFormat):
11+
stdout = Console(soft_wrap=True)
12+
report = read_report(path, stdout)
13+
if fmt == ReportFormat.markdown:
14+
format_markdown.print_report(report, stdout)
15+
else:
16+
format_text.print_report(report, stdout)

codelimit/commands/report/__init__.py

Whitespace-only changes.

codelimit/commands/report/format_markdown.py

Lines changed: 0 additions & 80 deletions
This file was deleted.

codelimit/commands/report/report.py

Lines changed: 0 additions & 90 deletions
This file was deleted.

codelimit/commands/scan.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
11
from pathlib import Path
22
from typing import Optional
33

4+
from rich.console import Console
5+
46
from codelimit.common.Configuration import Configuration
57
from codelimit.common.Scanner import scan_codebase
8+
from codelimit.common.report import format_text
69
from codelimit.common.report.Report import Report
710
from codelimit.common.report.ReportReader import ReportReader
811
from codelimit.common.report.ReportWriter import ReportWriter
912

1013

1114
def scan_command(path: Path):
15+
stdout = Console(soft_wrap=True)
1216
cache_dir = path.joinpath(".codelimit_cache").resolve()
1317
report_path = cache_dir.joinpath("codelimit.json").resolve()
1418
cached_report = _read_cached_report(report_path)
19+
format_text.print_totals_header(stdout)
1520
codebase = scan_codebase(path, cached_report)
1621
codebase.aggregate()
1722
report = Report(codebase, Configuration.repository)
23+
format_text.print_summary(report, stdout)
1824
if not cache_dir.exists():
1925
cache_dir.mkdir()
2026
cache_dir_tag = cache_dir.joinpath("CACHEDIR.TAG").resolve()

codelimit/common/ScanResultTable.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from rich import box
22
from rich.table import Table
3-
from rich.text import Text
43

54
from codelimit.common.ScanTotals import ScanTotals
65

@@ -29,23 +28,11 @@ def __init__(self, scan_totals: ScanTotals):
2928

3029
def _populate(self):
3130
for language_totals in self.scan_totals.languages_totals():
32-
hard_to_maintain = language_totals.hard_to_maintain
33-
if hard_to_maintain > 0:
34-
hard_to_maintain_text = Text(
35-
f"{hard_to_maintain:n}", style="dark_orange"
36-
)
37-
else:
38-
hard_to_maintain_text = "0"
39-
unmaintainable = language_totals.unmaintainable
40-
if unmaintainable > 0:
41-
unmaintainable_text = Text(f"{unmaintainable:n}", style="red")
42-
else:
43-
unmaintainable_text = "0"
4431
self.add_row(
4532
language_totals.language,
4633
f"{language_totals.files:n}",
4734
f"{language_totals.loc:n}",
4835
f"{language_totals.functions:n}",
49-
hard_to_maintain_text,
50-
unmaintainable_text,
36+
f"{language_totals.hard_to_maintain:n}",
37+
f"{language_totals.unmaintainable:n}"
5138
)

0 commit comments

Comments
 (0)