Initial upload of ai-code-audit-cli project
Some checks failed
Some checks failed
This commit is contained in:
83
src/core/config.py
Normal file
83
src/core/config.py
Normal file
@@ -0,0 +1,83 @@
|
||||
"""Configuration management for AI Code Audit CLI."""
|
||||
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class AuditConfig:
|
||||
"""Configuration for code audit operations."""
|
||||
|
||||
target_path: str
|
||||
output_format: str = "terminal"
|
||||
language_filter: Optional[str] = None
|
||||
severity_filter: Optional[str] = None
|
||||
verbose: bool = False
|
||||
no_color: bool = False
|
||||
quiet: bool = False
|
||||
max_file_size: int = 5 * 1024 * 1024
|
||||
excluded_patterns: list[str] = field(default_factory=lambda: [
|
||||
"__pycache__",
|
||||
".git",
|
||||
"node_modules",
|
||||
".venv",
|
||||
"venv",
|
||||
"*.pyc",
|
||||
".tox",
|
||||
".nox",
|
||||
"dist",
|
||||
"build",
|
||||
])
|
||||
ruff_config: Optional[str] = None
|
||||
bandit_config: Optional[str] = None
|
||||
|
||||
def validate(self) -> None:
|
||||
"""Validate configuration settings."""
|
||||
target = Path(self.target_path)
|
||||
if not target.exists():
|
||||
raise FileNotFoundError(f"Target path does not exist: {self.target_path}")
|
||||
|
||||
if not target.is_dir() and not target.is_file():
|
||||
raise ValueError(f"Invalid target path: {self.target_path}")
|
||||
|
||||
if self.max_file_size <= 0:
|
||||
raise ValueError("max_file_size must be positive")
|
||||
|
||||
valid_formats = {"terminal", "json", "markdown"}
|
||||
if self.output_format not in valid_formats:
|
||||
raise ValueError(f"Invalid output format: {self.output_format}. Must be one of {valid_formats}")
|
||||
|
||||
def should_scan_file(self, file_path: Path) -> bool:
|
||||
"""Check if a file should be scanned based on configuration."""
|
||||
if file_path.stat().st_size > self.max_file_size:
|
||||
return False
|
||||
|
||||
str_path = str(file_path)
|
||||
for pattern in self.excluded_patterns:
|
||||
if pattern in str_path:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
@classmethod
|
||||
def from_cli_args(
|
||||
cls,
|
||||
target_path: str,
|
||||
output_format: str = "terminal",
|
||||
language_filter: Optional[str] = None,
|
||||
severity_filter: Optional[str] = None,
|
||||
verbose: bool = False,
|
||||
no_color: bool = False,
|
||||
quiet: bool = False,
|
||||
) -> "AuditConfig":
|
||||
"""Create configuration from CLI arguments."""
|
||||
return cls(
|
||||
target_path=target_path,
|
||||
output_format=output_format,
|
||||
language_filter=language_filter,
|
||||
severity_filter=severity_filter,
|
||||
verbose=verbose,
|
||||
no_color=no_color,
|
||||
quiet=quiet,
|
||||
)
|
||||
Reference in New Issue
Block a user