| 523 | |
| 524 | |
| 525 | def matches_to_json(matches, text): |
| 526 | out = [] |
| 527 | for global_offset, m in matches: |
| 528 | line = text.count("\n", 0, global_offset) + 1 |
| 529 | out.append({ |
| 530 | "rule": _attr(m, "rule_id", "ruleId", default=""), |
| 531 | "category": _attr(m, "category", default=""), |
| 532 | "message": _attr(m, "message", default=""), |
| 533 | "line": line, |
| 534 | "offset": global_offset, |
| 535 | "length": _attr(m, "error_length", "errorLength", default=0), |
| 536 | "context": _attr(m, "context", default=""), |
| 537 | "replacements": list(_attr(m, "replacements", default=[])[:5]), |
| 538 | }) |
| 539 | return out |
| 540 | |
| 541 | |
| 542 | def main(): |