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