Skip to content

ci: fail a PR on duplicated code with a jscpd gate - #1914

Open
zancas wants to merge 1 commit into
devfrom
ci/code-duplication-gate
Open

zancas wants to merge 1 commit into
devfrom
ci/code-duplication-gate

Conversation

@zancas

@zancas zancas commented Nov 10, 2026

Copy link
Copy Markdown
Member

This PR adds a CI check that fails a PR on duplicated code.

The check

  • The code-duplication job runs jscpd 5.4.3 on TypeScript, TSX, Kotlin and Swift.
  • A clone is 50 tokens or 5 lines, inside one file or across files.
  • The job compares the PR with the tip of its base branch. One clone that the base branch lacks fails the job.
  • A push to main, dev or stable is compared with its parent commit.
  • The job runs under fail-all. A failure cancels the PR run.
  • The scan covers app, screens, ui, __tests__, __mocks__, .storybook, scripts, visual, android/app/src and ios.
  • The ignore list holds generated and vendored paths only.

dev holds 249 clones today (2.89% of 126,038 lines). The check accepts those 249 clones as the baseline. An edit that moves one of them makes it a new clone, and the job fails until the edit removes it.

Commands

  • yarn dupes zingolabs/dev runs the check locally.
  • yarn dupes:report lists each clone in the tree.

Tests

__tests__/codeDuplicationGate.unit.ts holds five tests. They pin the zero-clone limit, the two thresholds, the ignore list, the fail-all wiring and the baseline argument.

I ran the check locally on two trees. The clean tree exits 0. A tree with one copied file reports 1 new and exits 1.

tsc, eslint, prettier --check, depcheck and all 284 Jest suites pass locally.

After the merge

An administrator must add code-duplication / jscpd to the required status checks of dev. Until then the job fails the run but branch protection does not require it.

🤖 Generated with Claude Code

…ranch

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
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.

1 participant