(
checker: FileContentChecker, path: Path, code: str
)
| 107 | |
| 108 | |
| 109 | def _python_records( |
| 110 | checker: FileContentChecker, path: Path, code: str |
| 111 | ) -> list[dict[str, Any]]: |
| 112 | file_path = str(path) |
| 113 | if not checker.should_process_file(file_path): |
| 114 | return [] |
| 115 | |
| 116 | checker.check_file_content( |
| 117 | FileContent(path=file_path, content=code, lines=code.splitlines()) |
| 118 | ) |
| 119 | violations_by_path = getattr(checker, "violations", {}) |
| 120 | if isinstance(violations_by_path, CheckerResults): |
| 121 | file_violations = violations_by_path.violations.get( |
| 122 | file_path, violations_by_path.violations.get(_normalize_path(file_path)) |
| 123 | ) |
| 124 | if file_violations is None: |
| 125 | return [] |
| 126 | records: list[dict[str, Any]] = [] |
| 127 | for violation in file_violations.violations: |
| 128 | records.append( |
| 129 | { |
| 130 | "checker": checker.__class__.__name__, |
| 131 | "path": _normalize_path(file_path), |
| 132 | "line": violation.line_number, |
| 133 | "message": violation.content, |
| 134 | } |
| 135 | ) |
| 136 | return records |
| 137 | violations = violations_by_path.get( |
| 138 | file_path, violations_by_path.get(_normalize_path(file_path), []) |
| 139 | ) |
| 140 | if isinstance(violations, str): |
| 141 | return [ |
| 142 | { |
| 143 | "checker": checker.__class__.__name__, |
| 144 | "path": _normalize_path(file_path), |
| 145 | "line": 0, |
| 146 | "message": violations, |
| 147 | } |
| 148 | ] |
| 149 | records = [] |
| 150 | for item in violations: |
| 151 | converted = _legacy_violation_item_to_line_content(item) |
| 152 | records.append( |
| 153 | { |
| 154 | "checker": checker.__class__.__name__, |
| 155 | "path": _normalize_path(file_path), |
| 156 | "line": converted.line_number, |
| 157 | "message": converted.message, |
| 158 | } |
| 159 | ) |
| 160 | return records |
| 161 | |
| 162 | |
| 163 | def _rust_records( |
no test coverage detected