Coverage for analyzers/go.py: 92%

1"""Go source file analyzer -- assembles all metrics."""

2

3 from __future__ import annotations

4

5 from analyzers.shared import create_analyzer_file_fn, create_analyzer_source_fn

6 from parsers.go import parse, collect_functions, func_name

7 from metrics.lloc.go import count_lloc

8 from metrics.halstead.go import compute_halstead_go

9 from metrics.npath.go import compute_npath_go

10 from metrics.dtd.go import compute_dtd_go

11 from metrics.cognitive.go import compute_cognitive_go

12 from metrics.cyclomatic.go import compute_cyclomatic_go

13 from metrics.duplication.config import GO_CONFIG

14

15 analyze_source = create_analyzer_source_fn(

16 parse_fn=parse,

17 collect_functions_fn=collect_functions,

18 func_name_fn=func_name,

19 compute_cognitive_fn=compute_cognitive_go,

20 compute_halstead_fn=compute_halstead_go,

21 compute_npath_fn=compute_npath_go,

22 compute_dtd_fn=compute_dtd_go,

23 compute_cyclomatic_fn=compute_cyclomatic_go,

24 count_lloc_fn=count_lloc,

25 dup_config=GO_CONFIG,

26)

27

28

29 def analyze_file(filepath, timing_manager=None):

30 """Analyze a Go file and return cognitive complexity scores."""

31 return create_analyzer_file_fn(analyze_source)(

32 filepath, timing_manager=timing_manager

33 )