|
2 | 2 |
|
3 | 3 | import re |
4 | 4 | import sys |
5 | | -from dataclasses import dataclass, field, replace as dataclass_replace |
| 5 | +from dataclasses import dataclass, field |
| 6 | +from dataclasses import replace as dataclass_replace |
6 | 7 | from pathlib import Path |
7 | | -from typing import Any, Optional |
| 8 | +from typing import Any |
8 | 9 |
|
9 | 10 | # Config file is searched in this order within the scan root. |
10 | 11 | CONFIG_FILENAMES = (".env-auditorrc", "env-auditor.toml", "pyproject.toml") |
@@ -107,7 +108,7 @@ def load_config_from_file(path: Path) -> EnvAuditorConfig: |
107 | 108 | return _dict_to_config(raw, path) |
108 | 109 |
|
109 | 110 |
|
110 | | -def _read_config_raw(path: Path) -> tuple[Optional[dict[str, Any]], bool]: |
| 111 | +def _read_config_raw(path: Path) -> tuple[dict[str, Any] | None, bool]: |
111 | 112 | """Validate size, parse path as TOML, and return its env-auditor section. |
112 | 113 |
|
113 | 114 | Shared by :func:`load_config` (auto-discovery) and |
@@ -155,7 +156,7 @@ def _read_config_raw(path: Path) -> tuple[Optional[dict[str, Any]], bool]: |
155 | 156 | return raw, False |
156 | 157 |
|
157 | 158 |
|
158 | | -def _parse_toml_file(path: Path, is_pyproject: bool) -> Optional[dict[str, Any]]: |
| 159 | +def _parse_toml_file(path: Path, is_pyproject: bool) -> dict[str, Any] | None: |
159 | 160 | """Parse *path* as TOML and return the env-auditor section, or None. |
160 | 161 |
|
161 | 162 | Uses stdlib ``tomllib`` (Python 3.11+) with ``tomli`` fallback, |
@@ -250,9 +251,12 @@ def _minimal_toml_parse(path: Path) -> dict[str, Any]: |
250 | 251 | elif value.startswith("["): |
251 | 252 | # Use pre-compiled regex — not constructed from user input |
252 | 253 | current_node[key] = _LIST_ITEMS_RE.findall(value) |
253 | | - elif value.startswith('"') and value.endswith('"'): |
254 | | - current_node[key] = value[1:-1] |
255 | | - elif value.startswith("'") and value.endswith("'"): |
| 254 | + elif ( |
| 255 | + value.startswith('"') |
| 256 | + and value.endswith('"') |
| 257 | + or value.startswith("'") |
| 258 | + and value.endswith("'") |
| 259 | + ): |
256 | 260 | current_node[key] = value[1:-1] |
257 | 261 | else: |
258 | 262 | current_node[key] = value |
@@ -340,12 +344,12 @@ def _dict_to_config(raw: dict[str, Any], source: Path) -> EnvAuditorConfig: |
340 | 344 | def merge_cli_into_config( |
341 | 345 | cfg: EnvAuditorConfig, |
342 | 346 | *, |
343 | | - env_files: Optional[list[str]] = None, |
344 | | - exclude_dirs: Optional[list[str]] = None, |
345 | | - ignore_stale: Optional[bool] = None, |
346 | | - ignore_missing: Optional[bool] = None, |
347 | | - strict: Optional[bool] = None, |
348 | | - output_format: Optional[str] = None, |
| 347 | + env_files: list[str] | None = None, |
| 348 | + exclude_dirs: list[str] | None = None, |
| 349 | + ignore_stale: bool | None = None, |
| 350 | + ignore_missing: bool | None = None, |
| 351 | + strict: bool | None = None, |
| 352 | + output_format: str | None = None, |
349 | 353 | ) -> EnvAuditorConfig: |
350 | 354 | """Apply CLI overrides onto *cfg*, returning a new merged config. |
351 | 355 |
|
|
0 commit comments