Commit de95f16
committed
fix(dead-code,smell): 2 false-positive classes found dogfooding on KAW81 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).1 parent ba4d0d2 commit de95f16
4 files changed
Lines changed: 92 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
643 | 643 | | |
644 | 644 | | |
645 | 645 | | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
646 | 663 | | |
647 | 664 | | |
648 | 665 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1379 | 1379 | | |
1380 | 1380 | | |
1381 | 1381 | | |
| 1382 | + | |
1382 | 1383 | | |
1383 | 1384 | | |
1384 | 1385 | | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
| 1396 | + | |
| 1397 | + | |
| 1398 | + | |
| 1399 | + | |
| 1400 | + | |
| 1401 | + | |
| 1402 | + | |
| 1403 | + | |
| 1404 | + | |
| 1405 | + | |
1385 | 1406 | | |
1386 | 1407 | | |
1387 | 1408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
67 | 90 | | |
68 | 91 | | |
69 | 92 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
52 | 83 | | |
53 | 84 | | |
54 | 85 | | |
| |||
0 commit comments