Skip to content

Commit fd3acb8

Browse files
fix(cc): reduce CC violations 12→10
- ruby.py: _extract_ruby_body CC11→5 (_scan_ruby_body_lines) - analysis.py: _collect_node_data CC11→5 (_classify_node_into) All 278 tests pass. Co-authored-by: Koru Agent <agent@coru.dev>
1 parent 0c27952 commit fd3acb8

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

code2llm/core/lang/ruby.py

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,8 @@ def _is_ruby_end(line: str) -> bool:
1414
return line.startswith("end") and (len(line) == 3 or line.startswith("end "))
1515

1616

17-
def _extract_ruby_body(content: str, start_line: int) -> str:
18-
"""Extract Ruby function body from def to corresponding end."""
19-
lines = content.split("\n")
20-
if start_line < 1 or start_line > len(lines):
21-
return ""
22-
def_line_idx = start_line - 1
23-
while def_line_idx < len(lines):
24-
if re.match(r"^\s*def\s+", lines[def_line_idx]):
25-
break
26-
def_line_idx += 1
27-
if def_line_idx >= len(lines):
28-
return ""
17+
def _scan_ruby_body_lines(lines: list, def_line_idx: int) -> list:
18+
"""Scan lines after def_line_idx collecting body until matching end."""
2919
body_lines = []
3020
nested_depth = 1
3121
i = def_line_idx + 1
@@ -39,7 +29,22 @@ def _extract_ruby_body(content: str, start_line: int) -> str:
3929
nested_depth += 1
4030
body_lines.append(line)
4131
i += 1
42-
return "\n".join(body_lines)
32+
return body_lines
33+
34+
35+
def _extract_ruby_body(content: str, start_line: int) -> str:
36+
"""Extract Ruby function body from def to corresponding end."""
37+
lines = content.split("\n")
38+
if start_line < 1 or start_line > len(lines):
39+
return ""
40+
def_line_idx = start_line - 1
41+
while def_line_idx < len(lines):
42+
if re.match(r"^\s*def\s+", lines[def_line_idx]):
43+
break
44+
def_line_idx += 1
45+
if def_line_idx >= len(lines):
46+
return ""
47+
return "\n".join(_scan_ruby_body_lines(lines, def_line_idx))
4348

4449

4550
_RUBY_CC_PATTERN = re.compile(

code2llm/generators/llm_flow/analysis.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,21 @@ def score(fn: str) -> int:
9393
return picked
9494

9595

96+
def _classify_node_into(
97+
n: Dict, fn: str,
98+
decisions_by_func: dict, calls_by_func: dict
99+
) -> None:
100+
"""Append node data to decisions or calls dicts based on node type."""
101+
ntype = n.get("type")
102+
label = str(n.get("label") or "")
103+
if ntype == "IF":
104+
decisions_by_func[fn].append(_shorten(label, 120))
105+
elif ntype == "CALL":
106+
callee = _parse_call_label(label)
107+
if callee:
108+
calls_by_func[fn].append(callee)
109+
110+
96111
def _collect_node_data(
97112
nodes: Dict[int, Dict[str, Any]]
98113
) -> Tuple[Dict, Dict, Dict]:
@@ -109,14 +124,7 @@ def _collect_node_data(
109124
n.get("file") if isinstance(n.get("file"), str) else None,
110125
n.get("line") if isinstance(n.get("line"), int) else None,
111126
)
112-
ntype = n.get("type")
113-
label = str(n.get("label") or "")
114-
if ntype == "IF":
115-
decisions_by_func[fn].append(_shorten(label, 120))
116-
elif ntype == "CALL":
117-
callee = _parse_call_label(label)
118-
if callee:
119-
calls_by_func[fn].append(callee)
127+
_classify_node_into(n, fn, decisions_by_func, calls_by_func)
120128
return decisions_by_func, calls_by_func, loc_by_func
121129

122130

0 commit comments

Comments
 (0)