Skip to content

feat: reduce unused-code and duplicate-code false positives#18

Merged
PatrickDinh merged 5 commits into
mainfrom
feat/reduce-check-false-positives
Jul 21, 2026
Merged

feat: reduce unused-code and duplicate-code false positives#18
PatrickDinh merged 5 commits into
mainfrom
feat/reduce-check-false-positives

Conversation

@PatrickDinh

@PatrickDinh PatrickDinh commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

What

duplicate-code --max-warnings now gates on distinct duplicated regions instead of raw jscpd clones, and its failure output shows both counts. unused-code failures now include guidance on recognising and suppressing knip false positives before deleting code. verifyx init adds system binaries invoked by package.json scripts (uv, az, python, …) to knip's ignoreBinaries.

Why

Auditing a real consuming repo showed jscpd reporting the same duplication several times over, and knip flagging runtime-loaded files as unused — noise that inflates warning budgets and tempts an agent into deleting load-bearing code.

How

Clones merge when their ranges overlap on either side (union-find over pairs); the deduped count can only be lower than the raw one, so existing --max-warnings gates cannot newly fail. The ignoreBinaries candidates are curated against knip's IGNORED_GLOBAL_BINARIES so the scaffold never writes redundant entries that --treat-config-hints-as-errors would then flag.

- duplicate-code --max-warnings now gates on distinct duplicated regions:
  jscpd pairs whose ranges overlap on either side are merged (union-find),
  collapsing overlapping re-reports and N-file patterns reported as N-1
  pairs. Failure output shows both the deduped and raw counts.
  Benchmark: 106 raw clones -> 78 distinct regions on a real repo.
- unused-code failures now print false-positive advice: check for dynamic
  loading (directory scan + require(), glob-registered ORM entities) and
  system binaries before deleting; suppress via knip entry/ignoreBinaries.
- verifyx init detects system binaries invoked by package.json scripts
  that knip's IGNORED_GLOBAL_BINARIES doesn't cover (uv, az, python,
  terraform, ...) and adds them to knip ignoreBinaries.
@PatrickDinh
PatrickDinh marked this pull request as ready for review July 21, 2026 06:19

@staff0rd staff0rd left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review summary

Findings: 2 (blocker 0, major 0, minor 1, nit 1)

This is a focused, well-tested change that reduces false positives in the unused-code and duplicate-code checks (deduping jscpd clone regions, adding system-binary detection for knip's ignoreBinaries, and surfacing failure advice). Neither reviewer found a blocking or major defect; the only substantive issue is a narrow gap in shell-script binary detection that leaves one class of invocations unsuppressed.

Findings

  • minor: Binary detection misses command/process substitutions inside shell redirects
  • nit: jscpd report shape unverified against live tool output

Comment thread src/scaffold/detectSystemBinaries.ts Outdated
Comment thread src/checks/maxWarnings.ts
@PatrickDinh
PatrickDinh merged commit 5d01501 into main Jul 21, 2026
1 check passed
@PatrickDinh
PatrickDinh deleted the feat/reduce-check-false-positives branch July 21, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants