From f7dd3e0e4ee9e4e542219c3d071d747421f0453d Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Tue, 3 Feb 2026 10:30:03 +0000 Subject: [PATCH] Initial upload of ai-code-audit-cli project --- src/core/config.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 src/core/config.py diff --git a/src/core/config.py b/src/core/config.py new file mode 100644 index 0000000..ee0053c --- /dev/null +++ b/src/core/config.py @@ -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, + )