Coverage for metrics / cyclomatic / typescript.py: 100%
11 statements
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
« prev ^ index » next coverage.py v7.13.3, created at 2026-02-08 15:04 -0800
1"""McCabe cyclomatic complexity for TypeScript."""
3from __future__ import annotations
5from metrics.cyclomatic.shared import (
6 create_cyclomatic_computer,
7 create_cyclomatic_wrapper,
8)
11_TS_SKIP_TYPES = {
12 "function_declaration",
13 "function_expression",
14 "method_definition",
15 "generator_function_declaration",
16 "class_declaration",
17 "class_expression",
18 "arrow_function",
19}
21_TS_DECISION_TYPES = {
22 "if_statement",
23 "for_statement",
24 "for_in_statement",
25 "while_statement",
26 "do_statement",
27 "switch_case",
28 "catch_clause",
29 "ternary_expression",
30}
32_TS_LOGICAL_OPS = {"&&", "||", "??"}
35def _ts_skip_check(child, top_func) -> bool:
36 """Skip nested function declarations."""
37 if child.type in _TS_SKIP_TYPES and child is not top_func:
38 return True
39 return False
42_count_decisions = create_cyclomatic_computer(
43 _ts_skip_check, _TS_DECISION_TYPES, _TS_LOGICAL_OPS
44)
45compute_cyclomatic_ts = create_cyclomatic_wrapper(_count_decisions)