Coverage for metrics / cyclomatic / go.py: 92%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-08 15:04 -0800

1"""McCabe cyclomatic complexity for Go.""" 

2 

3from __future__ import annotations 

4 

5from parsers.go import is_named_func_literal 

6from metrics.cyclomatic.shared import ( 

7 create_cyclomatic_computer, 

8 create_cyclomatic_wrapper, 

9) 

10 

11 

12_GO_DECISION_TYPES = { 

13 "if_statement", 

14 "for_statement", 

15 "expression_case", 

16 "type_case", 

17 "communication_case", 

18} 

19 

20_GO_LOGICAL_OPS = {"&&", "||"} 

21 

22 

23def _go_skip_check(child, top_func) -> bool: 

24 """Skip nested function/method declarations.""" 

25 if ( 

26 child.type in ("function_declaration", "method_declaration") 

27 and child is not top_func 

28 ): 

29 return True 

30 if child.type == "func_literal" and child is not top_func: 

31 return is_named_func_literal(child) 

32 return False 

33 

34 

35_count_decisions = create_cyclomatic_computer( 

36 _go_skip_check, _GO_DECISION_TYPES, _GO_LOGICAL_OPS 

37) 

38compute_cyclomatic_go = create_cyclomatic_wrapper(_count_decisions)