D-20260812-07|重複碼量測與分階段零容忍¶
背景與驅動力¶
ESLint 逐檔執行,無法看守跨檔 token clone;專案也沒有可重現的重複碼報告。自行撰寫 detector 會承擔 parser、語言支援與跨平台維護,直接上零容忍 gate 則會讓既有 production clone 在分類前 阻塞所有變更,並可能誘使維護者抽取不安全的 conformance/security fixture。
考慮過的選項¶
- 維持 code review:沒有工具依賴,但無法持續量測跨檔 clone。
- 自寫 detector:可完全客製,卻重做成熟工具且增加 parser 維護面。
- 精確鎖定 jscpd,production/tests 分流,先報表清理再讓 production 零容忍:採納。
決定¶
使用精確鎖版 jscpd,不以 npx 動態下載;導入前驗證 license、transitive/optional dependency、
audit 與 Windows/Linux 執行。Production 與 tests 使用獨立設定:generated、vendor、fixture、specs
與特殊證據面明確排除;production 先 report-only、完成分類與清理後啟用 threshold 0,tests 維持
report-only。不得建立既有債 baseline,也不得為數字歸零抽掉 conformance、安全向量或測試意圖。
後果與影響¶
Production 的結構性重複有可執行零容忍防線,tests 則保留人工判斷有意重複的空間。jscpd 只偵測 token clone,不能取代語意重複 review;版本、parser、門檻與排除範圍都成為受文件與 fixture 看守的 工具鏈契約。