This is the duplication docker we use at Codacy to have jscpd support. You can also create a docker to integrate the tool and language of your choice!
You can create the docker by doing:
sbt graalvm-native-image:packageBin
docker build -t codacy-duplication-jscpd .You can run the docker with the following command:
docker run -it -v $srcDir:/src codacy-duplication-jscpdFor a faster development loop you can create a Docker image based on the JVM instead of creating a native-image:
sbt universal:stage
docker build -t codacy-duplication-jscpd --target dev .We use the codacy-plugins-test to test our external tools integration. You can follow the instructions there to make sure your tool is working as expected.
This section is written for an AI coding agent (or a human) tasked with updating this repo — most commonly bumping the wrapped jscpd npm package version, but also base image / orb bumps. Follow it top to bottom.
This is a Codacy duplication engine, not a pattern-based linting engine. It is a thin Scala wrapper (src/main/scala/com/codacy/duplication/jscpd/Jscpd.scala, built on codacy-duplication-scala-seed) that shells out to the real jscpd CLI (/node_modules/jscpd/bin/jscpd, installed as an npm dependency and baked into the Docker image) to detect copy-pasted code, parses its JSON report, and converts it into Codacy's DuplicationClone API model.
There is no docs/patterns.json and no pattern/rule catalog — duplication tools don't have configurable rules the way linters do. The only thing under docs/ is docs/duplication-tests/, a set of fixture directories (source files + expected results.xml) consumed by codacy-plugins-test's duplication-test mode. There is no doc-generation step and nothing under docs/ needs regenerating.
| File | What it controls | What to check |
|---|---|---|
package.json → dependencies.jscpd |
Which jscpd release is bundled | Bump the semver range/version to the target release. |
package-lock.json |
Locked/resolved jscpd version and its transitive deps | Regenerate via npm install after changing package.json — do not hand-edit. |
Dockerfile → ARG alpine_version |
Base OS image for both builder and runtime stages | Only bump if required (e.g. to pick up security fixes); check history for precedent (Bump alpine version, Fix vulnerabilities commits). |
build.sbt → com.codacy %% codacy-duplication-scala-seed |
The Codacy Scala seed/framework version this wrapper is built on | Bump only if the task explicitly calls for it; check the latest published version on Maven. |
.circleci/config.yml → codacy/base orb |
Shared CircleCI steps (checkout, sbt, docker publish) | Check the latest published orb version. |
.circleci/config.yml → codacy/plugins-test orb |
Runs codacy-plugins-test in CI (here with run_duplication_tests: true) |
Same as above. |
.github/dependabot.yml |
Automated npm bump PRs and any pinned exclusions | Check for a stale ignore entry (e.g. an old jscpd version pin) that may block or conflict with a manual bump. |
Git history confirms the pattern: every prior jscpd bump (e.g. build(deps): Bump jscpd from 4.0.5 to 4.2.4) touched only package.json and package-lock.json. Base-image and orb bumps are separate, occasional commits.
- Bump the version(s) as scoped by the task (e.g.
npm install jscpd@<version>to update bothpackage.jsonandpackage-lock.jsonconsistently — do not hand-edit the lockfile). - Compile and format:
sbt scalafmtSbt scalafmtAll(matches the CIpopulate_cache_and_compilejob). - Build the Docker image for a fast local dev loop:
(Or build the full native-image release with
sbt universal:stage docker build -t codacy-duplication-jscpd --target dev .sbt graalvm-native-image:packageBin && docker build -t codacy-duplication-jscpd ., matching CI'spublish_docker_localjob — slower, but what actually gets published.) - Run
codacy-plugins-testlocally before pushing — clone https://github.com/codacy/codacy-plugins-test and run its duplication-test mode against your local image tag and the fixtures indocs/duplication-tests/. - Iterate on failures, re-running only the relevant test command after each fix.
- Commit the version bump(s) (e.g.
package.json+package-lock.jsontogether) in one change. - Push and open a PR.
- Poll the PR's real CI checks until they all pass — local validation is NOT the finish line. After every push, run
gh pr checks <pr-url>and keep re-polling (short sleep while any check ispending) until all checks finish. If a check fails, fetch its actual log (don't guess), find the true root cause, fix it, push again (never--no-verify, never force-push), and re-poll. Repeat until every check is green. The CI environment's toolchain can differ from your local one, so a clean local run does not guarantee CI passes. Only stop iterating when every check passes, or you hit a genuine product/infra decision that needs a human.
- A jscpd major-version bump can change its CLI flags or JSON report shape (
jscpd-report.jsonstructure, field names likefragment/tokens/lines/firstFile/secondFile). Ifplugins_testduplication checks fail after a bump, diff the new jscpd CHANGELOG againstJscpd.scala's parsing logic before assuming a fixture is stale. package-lock.jsondiffs can be very large (hundreds of lines) for a single dependency bump due to transitive dependency shuffling — this is expected and should not be hand-trimmed..github/dependabot.ymlhas anignoreblock for a specific old jscpd version; if a manual bump target overlaps with an ignored version, dependabot won't reconcile it automatically — that's fine for a one-off manual bump but worth knowing.
- Version bump(s) reflected in all files that encode them (
package.json,package-lock.json, andDockerfile/build.sbt/.circleci/config.ymlif in scope). sbt scalafmtSbt scalafmtAllpasses.- Docker image builds successfully (dev target at minimum; native-image target if validating a release build).
codacy-plugins-testduplication-test commands pass locally against the freshly built image.- After pushing and opening/updating the PR, every CI check on it is green. Poll
gh pr checks <pr-url>and iterate on any failure until all pass.
Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.
- Identify new Static Analysis issues
- Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
- Auto-comments on Commits and Pull Requests
- Integrations with Slack, HipChat, Jira, YouTrack
- Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories
Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.
Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.
Codacy is free for Open Source projects.