-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Issue 15 invoking without tui (#16)
- Loading branch information
1 parent
167f154
commit 5dda87d
Showing
12 changed files
with
213 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import os | ||
from os.path import relpath | ||
from pathlib import Path | ||
|
||
import rich | ||
from rich.console import Console | ||
from rich.style import Style | ||
from rich.text import Text | ||
|
||
from codelimit.common.Measurement import Measurement | ||
from codelimit.common.utils import format_unit | ||
|
||
|
||
class CheckResult: | ||
def __init__(self): | ||
self.file_list: list[tuple[Path, list[Measurement]]] = [] | ||
self.hard_to_maintain = 0 | ||
self.unmaintainable = 0 | ||
|
||
def add(self, file: Path, measurements: list[Measurement]): | ||
self.file_list.append((file, measurements)) | ||
self.hard_to_maintain += len([m for m in measurements if 30 < m.value <= 60]) | ||
self.unmaintainable += len([m for m in measurements if m.value > 60]) | ||
|
||
def __len__(self): | ||
return len(self.file_list) | ||
|
||
def report(self): | ||
cwd_path = Path(os.getcwd()) | ||
stdout = Console() | ||
for file, measurements in self.file_list: | ||
for m in measurements: | ||
text = Text() | ||
if cwd_path in file.parents: | ||
text.append(relpath(file, cwd_path), style=Style(bold=True)) | ||
else: | ||
text.append(str(file), style="bold") | ||
text.append(":", style=Style(color="cyan")) | ||
text.append(str(m.start.line)) | ||
text.append(":", style=Style(color="cyan")) | ||
text.append(str(m.start.column)) | ||
text.append(":", style=Style(color="cyan")) | ||
text.append(" ") | ||
text.append(format_unit(m.unit_name, m.value)) | ||
stdout.print(text, soft_wrap=True) | ||
if self.hard_to_maintain > 0 or self.unmaintainable > 0: | ||
rich.print( | ||
f"{len(self.file_list)} files checked, " | ||
f"{self.hard_to_maintain + self.unmaintainable} functions need " | ||
f"refactoring." | ||
) | ||
else: | ||
rich.print( | ||
f"{len(self.file_list)} files checked, :sparkles: Refactoring not " | ||
f"necessary :sparkles:, happy coding!" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,9 @@ | ||
from dataclasses import dataclass | ||
|
||
from rich.text import Text | ||
|
||
from codelimit.common.Measurement import Measurement | ||
|
||
|
||
@dataclass | ||
class ReportUnit: | ||
file: str | ||
measurement: Measurement | ||
|
||
|
||
def format_report_unit(unit: ReportUnit) -> Text: | ||
name = unit.measurement.unit_name | ||
length = unit.measurement.value | ||
if length > 60: | ||
style = "red" | ||
elif length > 30: | ||
style = "dark_orange" | ||
elif length > 15: | ||
style = "yellow" | ||
else: | ||
style = "green" | ||
length_text = f"{length:3}" if length < 61 else "60+" | ||
styled_text = Text(length_text, style=style) | ||
return Text.assemble("[", styled_text, "] ", name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.