Coverage for analyzers / shared.py: 53%
15 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"""Shared analyzer functions to eliminate duplication across languages."""
3from __future__ import annotations
5from pathlib import Path
7from analyzers.common import analyze_source_generic
10def create_analyzer_file_fn(analyze_source_fn, **extra_kwargs):
11 """Factory to create analyze_file wrapper for language-specific analyzers."""
13 def analyze_file(filepath, timing_manager=None):
14 """Analyze a source file and return complexity scores."""
15 path = Path(filepath)
16 source = path.read_text()
17 result = analyze_source_fn(
18 source, timing_manager=timing_manager, **extra_kwargs
19 )
20 result.path = str(path)
21 return result
23 return analyze_file
26def create_analyzer_source_fn(
27 parse_fn,
28 collect_functions_fn,
29 func_name_fn,
30 compute_cognitive_fn,
31 compute_halstead_fn,
32 compute_npath_fn,
33 compute_dtd_fn,
34 compute_cyclomatic_fn,
35 count_lloc_fn,
36 dup_config,
37 check_patterns_fn=None,
38):
39 """Factory to create language-specific analyze_source function."""
41 def analyze_source(code, **kwargs):
42 return analyze_source_generic(
43 code,
44 parse_fn=parse_fn,
45 collect_functions_fn=collect_functions_fn,
46 func_name_fn=func_name_fn,
47 compute_cognitive_fn=compute_cognitive_fn,
48 compute_halstead_fn=compute_halstead_fn,
49 compute_npath_fn=compute_npath_fn,
50 compute_dtd_fn=compute_dtd_fn,
51 compute_cyclomatic_fn=compute_cyclomatic_fn,
52 count_lloc_fn=count_lloc_fn,
53 dup_config=dup_config,
54 check_patterns_fn=check_patterns_fn,
55 timing_manager=kwargs.get("timing_manager"),
56 )
58 return analyze_source