Run a scan and return the filtered issue list. Used by watch mode.
(
scan_path: Path,
config_path: Optional[Path],
severity_level: str,
ai_scan: bool,
syntax_warnings: bool = False,
debug: bool = False,
cache: Optional[IncrementalAstCache] = None,
)
| 298 | f"Warning: Could not read {display_path} - {e}", |
| 299 | fg="yellow", |
| 300 | ) |
| 301 | ) |
| 302 | if _stats_meta is not None: |
| 303 | _stats_meta['errors'] += 1 |
| 304 | |
| 305 | return results |
| 306 | |
| 307 | |
| 308 | def _scan_to_issues( |
| 309 | scan_path: Path, |
| 310 | config_path: Optional[Path], |
| 311 | severity_level: str, |
| 312 | ai_scan: bool, |
| 313 | syntax_warnings: bool = False, |
| 314 | debug: bool = False, |
| 315 | cache: Optional[IncrementalAstCache] = None, |
| 316 | ) -> List: |
| 317 | """Run a scan and return the filtered issue list. Used by watch mode.""" |
| 318 | config = load_config(config_path) |
| 319 | rules_toml_str = get_default_rules(ai_scan) |
| 320 | |
| 321 | if cache is None: |
| 322 | cache = get_cache(scan_path) |
| 323 | |
| 324 | baseline_path = ( |
| 325 | scan_path / ".pyspector_baseline.json" |
| 326 | if scan_path.is_dir() |
| 327 | else scan_path.parent / ".pyspector_baseline.json" |
| 328 | ) |
| 329 | ignored_fingerprints: set = set() |
| 330 | if baseline_path.exists(): |
| 331 | try: |
| 332 | with baseline_path.open("r") as f: |
| 333 | ignored_fingerprints = set( |
| 334 | json.load(f).get("ignored_fingerprints", []) |
| 335 | ) |
| 336 | except json.JSONDecodeError: |
| 337 | pass |
| 338 | |
| 339 | python_files_data = get_python_file_asts( |
| 340 | scan_path, |
| 341 | enable_syntax_warnings=syntax_warnings, |
| 342 | debug=debug, |
| 343 | exclude=list(config.get("exclude", [])), |
| 344 | cache=cache, |
| 345 | ) |
| 346 | |
| 347 | with _silence_fd1(not debug): |
| 348 | raw_issues = run_scan( |
| 349 | str(scan_path.resolve()), rules_toml_str, config, python_files_data |
| 350 | ) |
| 351 | |
| 352 | severity_map = {"LOW": 0, "MEDIUM": 1, "HIGH": 2, "CRITICAL": 3} |
| 353 | min_sev = severity_map[severity_level.upper()] |
| 354 |
no test coverage detected