-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.py
More file actions
69 lines (57 loc) · 1.92 KB
/
Copy pathconfig.py
File metadata and controls
69 lines (57 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
"""DeadCode configuration loader.
Reads .deadcode.yml from the project root. Supports:
ignore: list of gitignore-style patterns
categories: list of categories to enable (default: all)
fail_threshold: max findings before CI fails (default: -1 = disabled)
"""
from __future__ import annotations
from dataclasses import dataclass, field
from pathlib import Path
from typing import Any
@dataclass
class DeadCodeConfig:
"""Configuration loaded from .deadcode.yml."""
ignore: list[str] = field(default_factory=list)
categories: list[str] = field(
default_factory=lambda: [
"unused_export",
"dead_route",
"orphaned_css",
"unreferenced_component",
]
)
fail_threshold: int = -1 # -1 means disabled
@classmethod
def from_dict(cls, data: dict[str, Any]) -> DeadCodeConfig:
"""Create config from a parsed dict."""
return cls(
ignore=data.get("ignore", []),
categories=data.get(
"categories",
[
"unused_export",
"dead_route",
"orphaned_css",
"unreferenced_component",
],
),
fail_threshold=data.get("fail_threshold", -1),
)
@classmethod
def load(cls, project_dir: str | Path) -> DeadCodeConfig:
"""Load config from .deadcode.yml in project root, or return defaults."""
config_path = Path(project_dir) / ".deadcode.yml"
if not config_path.exists():
return cls()
try:
import yaml
except ImportError:
return cls()
try:
with open(config_path, encoding="utf-8") as f:
data = yaml.safe_load(f) or {}
except Exception:
return cls()
if not isinstance(data, dict):
return cls()
return cls.from_dict(data)