Coverage for src/qdrant_loader/core/chunking/strategy/code/metadata/documentation.py: 100%
11 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-09-08 06:05 +0000
1from __future__ import annotations
3import re
6def calculate_doc_coverage(content: str) -> dict[str, float | int | bool]:
7 function_count = len(re.findall(r"^\s*def\s+\w+", content, re.MULTILINE))
8 function_count += len(re.findall(r"^\s*function\s+\w+", content, re.MULTILINE))
10 class_count = len(re.findall(r"^\s*class\s+\w+", content, re.MULTILINE))
12 docstring_count = content.count('"""') // 2 + content.count("'''") // 2
14 comment_lines = len(
15 [
16 line
17 for line in content.split("\n")
18 if line.strip().startswith(("#", "//", "/*"))
19 ]
20 )
22 total_elements = function_count + class_count
23 doc_coverage = (docstring_count / total_elements * 100) if total_elements > 0 else 0
25 return {
26 "total_functions": function_count,
27 "total_classes": class_count,
28 "documented_elements": docstring_count,
29 "comment_lines": comment_lines,
30 "documentation_coverage_percent": doc_coverage,
31 "has_module_docstring": content.strip().startswith('"""')
32 or content.strip().startswith("'''"),
33 "avg_comment_density": (
34 comment_lines / len(content.split("\n")) if content else 0
35 ),
36 }