Skip to content

fix(dead-code,smell): 2 false-positive classes found dogfooding on real KAW81 API codebase - #325

Merged
Wolfvin merged 1 commit into
mainfrom
fix/dogfood-kaw81-false-positives
Aug 13, 2026
Merged

fix(dead-code,smell): 2 false-positive classes found dogfooding on real KAW81 API codebase#325
Wolfvin merged 1 commit into
mainfrom
fix/dogfood-kaw81-false-positives

Conversation

@Wolfvin

@Wolfvin Wolfvin commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Summary

Dogfooding codelens audit on a real ~29K-line TS/Express codebase (Coretax-Auto-Downloader, vps-deploy-kaw81/api/) surfaced 3 false-positive classes. 2 are fixed here with verified root cause + regression tests. The 3rd (registry_dead, deeper parser issue) is filed as #324 instead of guessed at.

1. unused_vars (deadcode_engine.py) — same-file-only scan false-flags exported values

This detector only counts occurrences within the same file. An export const X = ... is by definition meant for cross-file use, so it always found exactly 1 occurrence (the declaration) and flagged it. Real case: 7/7 Express rate-limiters (export const orderCreateRateLimiter = rateLimit(...)) used as app.post(path, orderCreateRateLimiter) in a different file — passed by reference, never re-mentioned in their own file.

Fix: skip any declaration immediately preceded by export — cross-file usage is unused_exports' job (correct import-graph walk), this same-file heuristic shouldn't duplicate a weaker version of it.

2. magic_values (smell_engine.py) — only excludes //, never /** */

JSDoc block-comment continuation lines start with *, not //, so they were never excluded. Every number in doc-comment prose got scanned as live code. Real case: routes/public/orders/create.ts flagged 17 "magic numbers" that were 100% GitHub issue references (#775, #1194) and range docs ([-90, 90]) inside JSDoc blocks.

Fix: track /* ... */ block-comment state, same pattern already used for Python's in_docstring.

Verification methodology

Both bugs verified with an A/B test, not just code reading: minimal repro fixture → git stash (bug reproduces) → git stash pop (bug gone). Repro fixtures matched the exact real-world nesting (Express router + asyncHandler wrapper for #1, JSDoc block structure for #2), not simplified guesses.

  • Full suite: 19 failures, all pre-existing (Windows path-separator / LSP-URI env issues already documented) — zero new failures, zero deadcode_engine/smell_engine failures.
  • New regression tests: test_exported_var_used_only_in_other_file_not_flagged (test_deadcode_engine.py), test_magic_values_ignores_numbers_in_block_comments (test_smell_engine.py).
  • Existing true-positive tests untouched and still pass (test_unused_variable_detection, test_python_unused_variable).

Not fixed here

registry_dead false-positive on same-file calls nested inside asyncHandler-wrapped route callbacks — filed as #324 with SQL evidence (malformed graph edges: source_id uses a raw line number instead of the <file>:0:<module> convention, target_id always NULL, 5 duplicate rows). 2 repro attempts failed to isolate a minimal case, so a fix here would've been a guess rather than a verified change.

Test plan

  • pytest tests/test_deadcode_engine.py -v — 25/25 pass (24 existing + 1 new)
  • pytest tests/test_smell_engine.py -v — 10/10 pass (9 existing + 1 new)
  • pytest tests/ --ignore=tests/test_integration.py --timeout=120 — 19 failures, all cross-checked against pre-existing baseline, zero new
  • A/B verified both fixes against real minimal repro (stash/pop), not just unit tests

🤖 Generated with Claude Code

…W81 API

Found while auditing a real ~29K-line TS/Express codebase (Coretax-Auto-
Downloader/vps-deploy-kaw81/api) with `codelens audit`. Both verified via
minimal repro + stash/pop A-B test (bug present pre-fix, gone post-fix),
not just inferred from reading the detector code.

1. unused_vars (deadcode_engine.py, _detect_unused_variables): this
   detector only counts occurrences WITHIN THE SAME FILE. An
   `export const X = ...` is by definition meant to be used from OTHER
   files, so it always found exactly 1 occurrence (the declaration) and
   false-flagged it. Real case: 7/7 Express rate-limiters
   (`export const orderCreateRateLimiter = rateLimit(...)`) used as
   `app.post(path, orderCreateRateLimiter)` in a different file — passed
   by reference, never re-mentioned in their own file. Fix: skip any
   declaration immediately preceded by `export` — cross-file usage is
   `unused_exports`' job (it walks the import graph correctly), this
   same-file heuristic must defer to it instead of duplicating a weaker
   version of the same check.

2. magic_values (smell_engine.py, _detect_magic_values): the line-skip
   logic only excluded single-line `//` comments. JSDoc block comments
   (`/** ... */`) were never tracked — continuation lines start with `*`,
   not `//`, so every number in doc-comment prose was scanned as if it
   were live code. Real case: routes/public/orders/create.ts flagged 17
   "magic numbers" that were 100% GitHub issue references (`#775`,
   `#1194`) and range docs (`[-90, 90]`) inside JSDoc. Fix: track
   /* ... */ block-comment state the same way in_docstring is already
   tracked for Python's """/'''.

Both fixes are pure line-skip additions to existing detectors — no
category removed, no threshold changed, existing true positives
untouched (test_unused_variable_detection / test_python_unused_variable
still pass unmodified).

New regression tests added per-engine (test_deadcode_engine.py,
test_smell_engine.py), matching existing test file structure.

Full suite: 19 failures, ALL pre-existing (Windows path separator /
LSP-URI env issues, listed in CONTEXT.md "Sudah kelar" baseline) —
zero new failures, zero deadcode_engine/smell_engine failures.

Not fixed here — filed as issue instead (needs deeper parser
investigation, didn't want to guess): registry_dead false-positive on
same-file function calls nested inside asyncHandler-wrapped Express
route callbacks. SQL evidence: graph_edges rows for the affected file
have source_id using a raw line number (`file.ts:30`) instead of the
established `<file>:0:<module>` synthetic-caller convention, target_id
always NULL, 5 duplicate rows, line=0 — strong signal of a parser bug
in how module-level/nested-callback calls get attributed, distinct from
the already-fixed #220 same-file-usage exemption path (which only
covers non-call references like const/static usage, not actual
function calls).
@Wolfvin Wolfvin added type: bug-fix Regression or broken behavior skip-design-doc labels Aug 13, 2026
@Wolfvin
Wolfvin merged commit 0615b07 into main Aug 13, 2026
1 of 7 checks passed
@Wolfvin
Wolfvin deleted the fix/dogfood-kaw81-false-positives branch August 13, 2026 03:23
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-design-doc type: bug-fix Regression or broken behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant