Find functions, classes, or files exceeding a line-count threshold. Useful for identifying decomposition targets, code-quality audits, and enforcing size limits during code review. Args: min_lines: Minimum line count to flag (default: 50). kind: Filter by node kind: Fun
(
min_lines: int = 50,
kind: str | None = None,
file_path_pattern: str | None = None,
limit: int = 50,
repo_root: str | None = None,
)
| 518 | |
| 519 | |
| 520 | def find_large_functions( |
| 521 | min_lines: int = 50, |
| 522 | kind: str | None = None, |
| 523 | file_path_pattern: str | None = None, |
| 524 | limit: int = 50, |
| 525 | repo_root: str | None = None, |
| 526 | ) -> dict[str, Any]: |
| 527 | """Find functions, classes, or files exceeding a line-count threshold. |
| 528 | |
| 529 | Useful for identifying decomposition targets, code-quality audits, |
| 530 | and enforcing size limits during code review. |
| 531 | |
| 532 | Args: |
| 533 | min_lines: Minimum line count to flag (default: 50). |
| 534 | kind: Filter by node kind: Function, Class, File, or Test. |
| 535 | file_path_pattern: Filter by file path substring (e.g. "components/"). |
| 536 | limit: Maximum results (default: 50). |
| 537 | repo_root: Repository root path. Auto-detected if omitted. |
| 538 | |
| 539 | Returns: |
| 540 | Oversized nodes with line counts, ordered largest first. |
| 541 | """ |
| 542 | store, root = _get_store(repo_root) |
| 543 | try: |
| 544 | nodes = store.get_nodes_by_size( |
| 545 | min_lines=min_lines, |
| 546 | kind=kind, |
| 547 | file_path_pattern=file_path_pattern, |
| 548 | limit=limit, |
| 549 | ) |
| 550 | |
| 551 | results = [] |
| 552 | for n in nodes: |
| 553 | d = node_to_dict(n) |
| 554 | d["line_count"] = ( |
| 555 | (n.line_end - n.line_start + 1) |
| 556 | if n.line_start and n.line_end |
| 557 | else 0 |
| 558 | ) |
| 559 | # Make file_path relative for readability |
| 560 | try: |
| 561 | d["relative_path"] = str(Path(n.file_path).relative_to(root)) |
| 562 | except ValueError: |
| 563 | d["relative_path"] = n.file_path |
| 564 | results.append(d) |
| 565 | |
| 566 | summary_parts = [ |
| 567 | f"Found {len(results)} node(s) with >= {min_lines} lines" |
| 568 | + (f" (kind={kind})" if kind else "") |
| 569 | + (f" matching '{file_path_pattern}'" if file_path_pattern else "") |
| 570 | + ":", |
| 571 | ] |
| 572 | for r in results[:10]: |
| 573 | summary_parts.append( |
| 574 | f" {r['line_count']:>4} lines | {r['kind']:>8} | " |
| 575 | f"{r['name']} ({r['relative_path']}:{r['line_start']})" |
| 576 | ) |
| 577 | if len(results) > 10: |
no test coverage detected