Getting Started

Configuration

Configure jscpd for your project.

Configuration File

Create a .jscpd.json file in your project root to configure jscpd:

.jscpd.json
{
  "threshold": 0,
  "reporters": ["html", "console"],
  "ignore": ["**/__snapshots__/**", "**/node_modules/**"],
  "absolute": true,
  "minLines": 5,
  "minTokens": 50
}

CLI Options

OptionDescriptionDefault
--min-linesMinimum lines in a code block to be detected5
--min-tokensMinimum tokens in a code block50
--max-linesMaximum lines in a code block1000
--max-sizeMaximum file size in bytes100kb
--thresholdThreshold for duplication percentage0
--reportersReporters to useconsole
--outputOutput directory for reports./report
--formatFormat for source code-
--patternGlob pattern for files-
--ignorePatterns to ignore-
--gitignoreUse .gitignore patternstrue
--blameShow git blame infofalse
--silentDon't output to consolefalse
--absoluteUse absolute pathsfalse
--no-symlinksDon't follow symlinksfalse
--skip-localSkip local duplicatesfalse
--formats-extsDefine custom format extensions-

Examples

Basic scan

jscpd ./src

With pattern matching

jscpd --pattern "**/*.ts" ./src

Multiple reporters

jscpd --reporters html,json,console ./src

Custom threshold

Fail if duplication exceeds 5%:

jscpd --threshold 5 ./src

Ignore specific patterns

jscpd --ignore "**/*.test.ts,**/__mocks__/**" ./src

Package.json Configuration

You can also configure jscpd in your package.json:

package.json
{
  "jscpd": {
    "threshold": 0,
    "reporters": ["html", "console"],
    "ignore": ["**/node_modules/**"],
    "absolute": true
  }
}