Scan a single file. Returns list of (func_name, line_number, path_str, raw_line_str).
(
path: Path,
func_rx: Pattern[str],
noqa_markers: tuple[str, ...]
)
| 85 | return re.compile(r"(?<!\w)(?:" + "|".join(map(re.escape, funcs)) + r")(?!\w)") |
| 86 | |
| 87 | def scan_file( |
| 88 | path: Path, |
| 89 | func_rx: Pattern[str], |
| 90 | noqa_markers: tuple[str, ...] |
| 91 | ) -> list[tuple[str, int, str, str]]: |
| 92 | """ |
| 93 | Scan a single file. |
| 94 | Returns list of (func_name, line_number, path_str, raw_line_str). |
| 95 | """ |
| 96 | hits: list[tuple[str, int, str, str]] = [] |
| 97 | in_block = False |
| 98 | noqa_set = set(noqa_markers) |
| 99 | |
| 100 | try: |
| 101 | with path.open("r", encoding="utf-8", errors="ignore") as f: |
| 102 | for lineno, raw in enumerate(f, 1): |
| 103 | # Skip if approved by noqa markers |
| 104 | if any(mark in raw for mark in noqa_set): |
| 105 | continue |
| 106 | |
| 107 | # Remove comments; if nothing remains, skip |
| 108 | code, in_block = strip_comments(raw.rstrip("\n"), in_block) |
| 109 | if not code.strip(): |
| 110 | continue |
| 111 | |
| 112 | # Find all suspicious calls in non-comment code |
| 113 | for m in func_rx.finditer(code): |
| 114 | hits.append((m.group(0), lineno, str(path), raw.rstrip("\n"))) |
| 115 | except FileNotFoundError: |
| 116 | # File may have disappeared; ignore gracefully |
| 117 | pass |
| 118 | return hits |
| 119 | |
| 120 | |
| 121 | def main(argv: list[str] | None = None) -> int: |