Return True if this node is a file-level hub node (e.g. 'client', 'models') or an AST method stub (e.g. '.auth_flow()', '.__init__()'). These are synthetic nodes created by the AST extractor and should be excluded from god nodes, surprising connections, and knowledge gap reporting.
(G: nx.Graph, node_id: str)
| 9 | |
| 10 | |
| 11 | def _is_file_node(G: nx.Graph, node_id: str) -> bool: |
| 12 | """ |
| 13 | Return True if this node is a file-level hub node (e.g. 'client', 'models') |
| 14 | or an AST method stub (e.g. '.auth_flow()', '.__init__()'). |
| 15 | |
| 16 | These are synthetic nodes created by the AST extractor and should be excluded |
| 17 | from god nodes, surprising connections, and knowledge gap reporting. |
| 18 | """ |
| 19 | label = G.nodes[node_id].get("label", "") |
| 20 | if not label: |
| 21 | return False |
| 22 | # File-level hub: label is a filename with a code extension |
| 23 | if label.split(".")[-1] in ("py", "ts", "js", "go", "rs", "java", "rb", "cpp", "c", "h"): |
| 24 | return True |
| 25 | # Method stub: AST extractor labels methods as '.method_name()' |
| 26 | if label.startswith(".") and label.endswith("()"): |
| 27 | return True |
| 28 | # Module-level function stub: labeled 'function_name()' - only has a contains edge |
| 29 | # These are real functions but structurally isolated by definition; not a gap worth flagging |
| 30 | if label.endswith("()") and G.degree(node_id) <= 1: |
| 31 | return True |
| 32 | return False |
| 33 | |
| 34 | |
| 35 | def god_nodes(G: nx.Graph, top_n: int = 10) -> list[dict]: |
no test coverage detected