Skip to content

Commit abd09d9

Browse files
committed
feat: upgrade remote scanning and reporting (roast/scanner.py)
1 parent 825e1ef commit abd09d9

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

roast/scanner.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass
6-
from pathlib import Path
76
import logging
7+
from pathlib import Path
88
from typing import Iterable
99

1010
LOGGER = logging.getLogger(__name__)
@@ -19,6 +19,14 @@
1919
".cfg",
2020
".md",
2121
}
22+
CONFIG_FILENAMES = {
23+
"package-lock.json",
24+
"yarn.lock",
25+
"pnpm-lock.yaml",
26+
"poetry.lock",
27+
"pylintrc",
28+
"eslint.config.js",
29+
}
2230

2331
LANGUAGE_BY_EXTENSION = {
2432
".py": "python",
@@ -74,14 +82,7 @@ def _infer_language(path: Path) -> str:
7482
def _is_config_file(path: Path) -> bool:
7583
if path.suffix.lower() in CONFIG_EXTENSIONS:
7684
return True
77-
return path.name.lower() in {
78-
"package-lock.json",
79-
"yarn.lock",
80-
"pnpm-lock.yaml",
81-
"poetry.lock",
82-
"pylintrc",
83-
"eslint.config.js",
84-
}
85+
return path.name.lower() in CONFIG_FILENAMES
8586

8687

8788
def _should_skip_path(path: Path) -> bool:
@@ -92,7 +93,12 @@ def _should_skip_path(path: Path) -> bool:
9293
return name == ".env" or name.startswith(".env.")
9394

9495

95-
def scan_repo(path: str | Path, extensions: Iterable[str], max_files: int) -> list[FileResult]:
96+
def scan_repo(
97+
path: str | Path,
98+
extensions: Iterable[str],
99+
max_files: int,
100+
include_config: bool = False,
101+
) -> list[FileResult]:
96102
"""Scan a repository path and return parsed source files."""
97103
root = Path(path).expanduser().resolve()
98104
ext_filter = _normalize_extensions(extensions)
@@ -103,9 +109,12 @@ def scan_repo(path: str | Path, extensions: Iterable[str], max_files: int) -> li
103109
continue
104110
if _should_skip_path(file_path.relative_to(root)):
105111
continue
106-
if ext_filter and file_path.suffix.lower() not in ext_filter:
112+
113+
is_config_file = _is_config_file(file_path)
114+
if ext_filter and file_path.suffix.lower() not in ext_filter and not (include_config and is_config_file):
107115
continue
108-
priority = 1 if _is_config_file(file_path) else 0
116+
117+
priority = 1 if is_config_file else 0
109118
candidates.append((priority, file_path))
110119

111120
candidates.sort(key=lambda item: (item[0], str(item[1]).lower()))

0 commit comments

Comments
 (0)