Skip to content

Commit c6222b6

Browse files
clanker-loverclaude
andcommitted
Skip file-level line-count scoring for HTML templates and test files
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 98ca1fb commit c6222b6

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

codedocent/quality.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
from __future__ import annotations
44

5+
import os
6+
57
from codedocent.parser import CodeNode
68

79
# Quality scoring thresholds: (yellow_threshold, red_threshold)
@@ -99,8 +101,27 @@ def _score_radon(node: CodeNode) -> tuple[str, str | None]:
99101
return "clean", None
100102

101103

104+
def _is_exempt_file(node: CodeNode) -> bool:
105+
"""Check if a file node should skip line-count scoring.
106+
107+
HTML templates and test files are naturally long, so line count
108+
does not indicate poor quality for these file types.
109+
"""
110+
if node.node_type != "file":
111+
return False
112+
if node.language == "html":
113+
return True
114+
if node.language is None and node.name.endswith(".html"):
115+
return True
116+
if os.path.basename(node.name).startswith("test_"):
117+
return True
118+
return False
119+
120+
102121
def _score_line_count(node: CodeNode) -> tuple[str, str | None]:
103122
"""Score based on line-count thresholds (two-tier: yellow/red)."""
123+
if _is_exempt_file(node):
124+
return "clean", None
104125
thresholds = LINE_THRESHOLDS.get(node.node_type)
105126
if thresholds and node.line_count:
106127
yellow, red = thresholds

tests/test_analyzer.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,3 +541,39 @@ def test_quality_directory_returns_none():
541541
quality, warnings = _score_quality(node)
542542
assert quality is None
543543
assert warnings is None
544+
545+
546+
# ---------------------------------------------------------------------------
547+
# Phase 8: Exempt HTML templates and test files from line-count scoring
548+
# ---------------------------------------------------------------------------
549+
550+
551+
def test_quality_html_file_exempt_from_line_count():
552+
from codedocent.quality import _score_quality
553+
554+
node = _make_file_node(name="base.html", lang="html", source="<div></div>\n")
555+
node.line_count = 1500
556+
quality, warnings = _score_quality(node)
557+
assert quality == "clean"
558+
assert warnings is None
559+
560+
561+
def test_quality_test_file_exempt_from_line_count():
562+
from codedocent.quality import _score_quality
563+
564+
node = _make_file_node(name="test_foo.py", lang="python", source="x = 1\n")
565+
node.line_count = 600
566+
quality, warnings = _score_quality(node)
567+
assert quality == "clean"
568+
assert warnings is None
569+
570+
571+
def test_quality_regular_python_file_still_scored():
572+
from codedocent.quality import _score_quality
573+
574+
node = _make_file_node(name="app.py", lang="python", source="x = 1\n")
575+
node.line_count = 600
576+
quality, warnings = _score_quality(node)
577+
assert quality == "complex"
578+
assert warnings is not None
579+
assert any("600 lines" in w for w in warnings)

0 commit comments

Comments
 (0)