fix: resolve CI/CD linting and formatting issues
Some checks failed
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / build (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled

- Replaced deprecated typing.Dict/List/Tuple with native types (UP035)
- Removed unused imports across all modules
- Fixed unused variables by replacing with _ prefix
- Added missing Optional type imports
- Reorganized imports for proper sorting (I001)
- Applied black formatting to all source files
This commit is contained in:
2026-02-02 08:52:08 +00:00
parent 460263345c
commit 62021dd68b

View File

@@ -1,18 +1,18 @@
"""JSON output formatter.""" '''JSON output formatter.'''
import json import json
from typing import Any, Dict, List from typing import Any
from loglens.analyzers.analyzer import AnalysisResult from loglens.analyzers.analyzer import AnalysisResult
from loglens.parsers.base import ParsedLogEntry
from loglens.formatters.base import OutputFormatter from loglens.formatters.base import OutputFormatter
from loglens.parsers.base import ParsedLogEntry
class JSONFormatter(OutputFormatter): class JSONFormatter(OutputFormatter):
"""Formats output as JSON.""" '''Formats output as JSON.'''
def format(self, data: Any) -> str: def format(self, data: Any) -> str:
"""Format data as JSON.""" '''Format data as JSON.'''
if isinstance(data, AnalysisResult): if isinstance(data, AnalysisResult):
return self._format_analysis_result(data) return self._format_analysis_result(data)
elif isinstance(data, list): elif isinstance(data, list):
@@ -21,36 +21,36 @@ class JSONFormatter(OutputFormatter):
return json.dumps(data, default=str, indent=2) return json.dumps(data, default=str, indent=2)
def _format_analysis_result(self, result: AnalysisResult) -> str: def _format_analysis_result(self, result: AnalysisResult) -> str:
"""Format analysis result as JSON.""" '''Format analysis result as JSON.'''
output = { output = {
"summary": { "summary": {
"total_lines": result.total_lines, "total_lines": result.total_lines,
"parsed_entries": result.parsed_count, "parsed_entries": result.parsed_count,
"format_detected": result.format_detected.value, "format_detected": result.format_detected.value,
"analysis_time": result.analysis_time.isoformat() "analysis_time": result.analysis_time.isoformat(),
}, },
"severity_breakdown": result.severity_breakdown, "severity_breakdown": result.severity_breakdown,
"pattern_matches": result.pattern_matches, "pattern_matches": result.pattern_matches,
"top_errors": result.top_errors, "top_errors": result.top_errors,
"host_breakdown": result.host_breakdown, "host_breakdown": result.host_breakdown,
"suggestions": result.suggestions "suggestions": result.suggestions,
} }
if result.time_range: if result.time_range:
output["time_range"] = { output["time_range"] = {
"start": result.time_range[0].isoformat(), "start": result.time_range[0].isoformat(),
"end": result.time_range[1].isoformat() "end": result.time_range[1].isoformat(),
} }
return json.dumps(output, default=str, indent=2) return json.dumps(output, default=str, indent=2)
def _format_entries(self, entries: List[ParsedLogEntry]) -> str: def _format_entries(self, entries: list[ParsedLogEntry]) -> str:
"""Format log entries as JSON array.""" '''Format log entries as JSON array.'''
output = [entry.to_dict() for entry in entries] output = [entry.to_dict() for entry in entries]
return json.dumps(output, default=str, indent=2) return json.dumps(output, default=str, indent=2)
def format_entries_compact(self, entries: List[ParsedLogEntry]) -> str: def format_entries_compact(self, entries: list[ParsedLogEntry]) -> str:
"""Format entries as compact JSON (one per line).""" '''Format entries as compact JSON (one per line).'''
lines = [] lines = []
for entry in entries: for entry in entries:
lines.append(json.dumps(entry.to_dict(), default=str)) lines.append(json.dumps(entry.to_dict(), default=str))