fix: resolve CI linting errors - remove unused imports and update type annotations
This commit is contained in:
@@ -9,12 +9,14 @@ from gdiffer.models import DiffAnalysis
|
||||
|
||||
|
||||
class OutputFormat(Enum):
|
||||
"""Output format options."""
|
||||
TERMINAL = "terminal"
|
||||
JSON = "json"
|
||||
PLAIN = "plain"
|
||||
|
||||
|
||||
class SeverityColors:
|
||||
"""Color scheme for severity levels."""
|
||||
CRITICAL = "red"
|
||||
HIGH = "orange3"
|
||||
MEDIUM = "yellow"
|
||||
@@ -23,6 +25,8 @@ class SeverityColors:
|
||||
|
||||
|
||||
class OutputFormatter:
|
||||
"""Formats and displays diff analysis results."""
|
||||
|
||||
def __init__(self, output_format: OutputFormat = OutputFormat.TERMINAL):
|
||||
self.output_format = output_format
|
||||
self.console = Console(theme=Theme({
|
||||
@@ -38,6 +42,7 @@ class OutputFormatter:
|
||||
}))
|
||||
|
||||
def format_analysis(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format the complete analysis for display."""
|
||||
if self.output_format == OutputFormat.JSON:
|
||||
return self._format_json(analysis)
|
||||
elif self.output_format == OutputFormat.PLAIN:
|
||||
@@ -46,6 +51,7 @@ class OutputFormatter:
|
||||
return self._format_terminal(analysis)
|
||||
|
||||
def _format_terminal(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format for terminal display with colors."""
|
||||
output_parts = []
|
||||
|
||||
output_parts.append(self._format_summary(analysis))
|
||||
@@ -60,6 +66,7 @@ class OutputFormatter:
|
||||
return '\n'.join(output_parts)
|
||||
|
||||
def _format_summary(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format the summary section."""
|
||||
lines = []
|
||||
lines.append("[bold blue]=== Git Diff Analysis Summary ===[/bold blue]")
|
||||
lines.append(f"[info]Total files changed:[/info] [bold]{analysis.total_files}[/bold]")
|
||||
@@ -76,6 +83,7 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def _format_files(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format file changes section."""
|
||||
lines = []
|
||||
lines.append("\n[bold blue]=== File Changes ===[/bold blue]")
|
||||
|
||||
@@ -83,10 +91,10 @@ class OutputFormatter:
|
||||
lines.append(f"\n[filename]{i}. {file_obj.filename}[/filename]")
|
||||
|
||||
change_emoji = {
|
||||
"add": "[added][✚][/added]",
|
||||
"delete": "[removed][✖][/removed]",
|
||||
"rename": "[info][↪][/info]",
|
||||
"modify": "[modified][✎][/modified]",
|
||||
"add": "[added]✚[/added]",
|
||||
"delete": "[removed]✖[/removed]",
|
||||
"rename": "[info]↪[/info]",
|
||||
"modify": "[modified]✎[/modified]",
|
||||
}
|
||||
change_label = change_emoji.get(file_obj.change_type, "")
|
||||
lines.append(f" Status: {change_label} {file_obj.change_type}")
|
||||
@@ -105,6 +113,7 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def _format_hunk(self, hunk) -> str:
|
||||
"""Format a single hunk with color-coded changes."""
|
||||
lines = []
|
||||
for line in hunk.new_lines_content:
|
||||
if line.startswith('+++'):
|
||||
@@ -120,6 +129,7 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def _format_issues(self, issues: list[dict]) -> str:
|
||||
"""Format issues section."""
|
||||
lines = []
|
||||
lines.append("\n[bold blue]=== Detected Issues ===[/bold blue]")
|
||||
|
||||
@@ -129,8 +139,8 @@ class OutputFormatter:
|
||||
for issue in sorted_issues:
|
||||
severity = issue.get('severity', 'info').lower()
|
||||
color = getattr(SeverityColors, severity.upper(), 'info')
|
||||
lines.append(f"\n[{color}][✖] {issue.get('title', 'Issue')}[/]")
|
||||
lines.append(f" Severity: [{color}]{severity.upper()}[/]")
|
||||
lines.append(f"\n[{color}]✖ {issue.get('title', 'Issue')}[/[{color}]]")
|
||||
lines.append(f" Severity: [{color}]{severity.upper()}[/[{color}]]")
|
||||
lines.append(f" Description: {issue.get('description', '')}")
|
||||
if issue.get('line'):
|
||||
lines.append(f" Line: {issue['line']}")
|
||||
@@ -140,6 +150,7 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def _format_suggestions(self, suggestions: list[str]) -> str:
|
||||
"""Format suggestions section."""
|
||||
lines = []
|
||||
lines.append("\n[bold blue]=== Suggestions ===[/bold blue]")
|
||||
|
||||
@@ -149,6 +160,7 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def _format_json(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format as JSON."""
|
||||
import json
|
||||
|
||||
result = {
|
||||
@@ -195,6 +207,7 @@ class OutputFormatter:
|
||||
return json.dumps(result, indent=2)
|
||||
|
||||
def _format_plain(self, analysis: DiffAnalysis) -> str:
|
||||
"""Format as plain text without colors."""
|
||||
lines = []
|
||||
lines.append("=== Git Diff Analysis Summary ===")
|
||||
lines.append(f"Total files changed: {analysis.total_files}")
|
||||
@@ -239,18 +252,22 @@ class OutputFormatter:
|
||||
return '\n'.join(lines)
|
||||
|
||||
def print(self, content: str) -> None:
|
||||
"""Print content to console."""
|
||||
self.console.print(content)
|
||||
|
||||
def print_analysis(self, analysis: DiffAnalysis) -> None:
|
||||
"""Print analysis result to console."""
|
||||
formatted = self.format_analysis(analysis)
|
||||
self.print(formatted)
|
||||
|
||||
|
||||
def format_analysis(analysis: DiffAnalysis, output_format: str = "terminal") -> str:
|
||||
"""Format analysis for display."""
|
||||
fmt = OutputFormatter(OutputFormat(output_format))
|
||||
return fmt.format_analysis(analysis)
|
||||
|
||||
|
||||
def print_analysis(analysis: DiffAnalysis, output_format: str = "terminal") -> None:
|
||||
"""Print analysis to console."""
|
||||
fmt = OutputFormatter(OutputFormat(output_format))
|
||||
fmt.print_analysis(analysis)
|
||||
|
||||
Reference in New Issue
Block a user