fix(health): use whole-file NLOC for health file metrics#387
Open
joptimus wants to merge 1 commit into
Open
Conversation
…unction-body sum health_file_metrics.nloc previously stored the sum of per-function body NLOC, which undercount files with significant top-level code or logic spread across middleware chains. Consumers (churn risk, repo score weighting, effort buckets) already assumed a whole-file value. FileComplexity gains a file_nloc field populated by walk_file: - successful parse: count lines with at least one non-comment token (tree traversal skips comment subtrees, so comment-only and block-comment-only lines are excluded; code lines with trailing comments still count) - unsupported language / parse failure: plain non-blank line fallback so file_nloc is never zero on readable source _evaluate_file in engine.py now reads fcx.file_nloc directly instead of summing FunctionComplexity.nloc values. Per-function nloc is unchanged — biomarkers that need it (large_method, brain_method, etc.) still use the function-level field.
|
✅ Health: 7.0 (unchanged)
🩹 Review priority (files here with the most recent bug-fix history — defects cluster, so review these first)
🔥 Hotspots touched (2)
🔗 Hidden coupling (2 files)
📊 Full report · ⭐ Star Repowise · 📥 Install bot · Last updated 2026-06-05 20:52 UTC |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
health_file_metrics.nlocstoring the sum of detected function-body NLOC instead of whole-file NLOC.FileComplexity.file_nloc. On successful parses it counts source lines with at least one non-comment token, so comment-only lines are excluded while code with trailing comments still counts. Parser failures and unsupported languages fall back to a plain non-blank line count.HealthAnalyzer._evaluate_fileto usefcx.file_nloc. Per-functionnlocis unchanged for biomarkers that need function-level measurements.Context
Fixes #375.
Route-style files and modules with top-level logic could previously store very small NLOC values because top-level callbacks, imports, wiring, and config were outside detected function bodies. That made downstream health signals like churn risk and effort buckets look much worse than they should.
Test plan
file_nloc.uv run pytest tests/unit/health -q- 270 passed