Parse source and return SPI001 violations not suppressed by noqa.
(path: str, source: str)
| 55 | |
| 56 | |
| 57 | def check_file(path: str, source: str) -> list[tuple[int, str]]: |
| 58 | """Parse source and return SPI001 violations not suppressed by noqa.""" |
| 59 | try: |
| 60 | tree = ast.parse(source, filename=path) |
| 61 | except SyntaxError: |
| 62 | return [] |
| 63 | |
| 64 | visitor = SysPathVisitor() |
| 65 | visitor.visit(tree) |
| 66 | |
| 67 | # Silently filter out violations on lines with noqa SPI001 suppression |
| 68 | lines = source.splitlines() |
| 69 | result: list[tuple[int, str]] = [] |
| 70 | for line_no, message in visitor.violations: |
| 71 | if line_no <= len(lines) and _NOQA_RE.search(lines[line_no - 1]): |
| 72 | continue |
| 73 | result.append((line_no, message)) |
| 74 | return result |
| 75 | |
| 76 | |
| 77 | def collect_python_files( |
no test coverage detected