Copy/paste detector for source code that supports 150+ programming languages and provides both CLI and programmatic APIs
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Command-line interface integration allowing programmatic access to CLI functionality with full argument processing and configuration file support.
Processes command-line arguments and executes clone detection with CLI-style behavior.
/**
* CLI entry point function that processes command line arguments
* @param argv - Command line arguments array (typically process.argv)
* @param exitCallback - Optional callback for process exit with exit code
* @returns Promise resolving to array of detected clones
*/
function jscpd(
argv: string[],
exitCallback?: (code: number) => {}
): Promise<IClone[]>;Usage Examples:
import { jscpd } from "jscpd";
// Basic programmatic CLI usage
const clones = await jscpd([
"node", "jscpd", "./src"
]);
// With CLI options
const clones = await jscpd([
"node", "jscpd",
"./src", "./lib",
"--min-lines", "5",
"--min-tokens", "50",
"--format", "javascript,typescript",
"--reporters", "console,json",
"--output", "./reports",
"--threshold", "10"
]);
// With exit callback for CI integration
const clones = await jscpd([
"node", "jscpd", "./src",
"--threshold", "5"
], (exitCode) => {
console.log(`JSCPD finished with exit code: ${exitCode}`);
process.exit(exitCode);
});Creates and configures Commander.js CLI with all available options.
/**
* Initializes Commander.js CLI with all jscpd options
* @param packageJson - Package metadata for version and description
* @param argv - Command line arguments array
* @returns Configured Commander instance
*/
function initCli(packageJson: any, argv: string[]): Command;Usage Example:
import { initCli } from "jscpd";
import { readJSONSync } from "fs-extra";
const packageJson = readJSONSync("./package.json");
const cli = initCli(packageJson, process.argv);
// Access parsed CLI options
console.log("Min lines:", cli.minLines);
console.log("Format:", cli.format);
console.log("Paths:", cli.args);All CLI options available through the command-line interface:
# Specify paths to analyze
jscpd /path/to/source /another/path
# Use glob patterns
jscpd --pattern "src/**/*.js"
jscpd -p "**/*.{js,ts}"
# Specify file formats
jscpd --format javascript,typescript
jscpd -f "javascript,python"
# Custom format extensions
jscpd --formats-exts "javascript:es,es6;dart:dt"# Minimum lines for duplication
jscpd --min-lines 5
jscpd -l 5
# Minimum tokens for duplication
jscpd --min-tokens 50
jscpd -k 50
# Maximum lines to analyze
jscpd --max-lines 1000
jscpd -x 1000
# Maximum file size
jscpd --max-size 1mb
jscpd -z 120kb
# Detection quality mode
jscpd --mode strict
jscpd -m mild# Ignore files by glob pattern
jscpd --ignore "**/*.test.js,**/node_modules/**"
jscpd -i "**/*.spec.ts"
# Ignore code blocks by regex
jscpd --ignore-pattern "DEBUG,TODO,FIXME"
# Respect .gitignore
jscpd --gitignore
jscpd -g
# Skip local folder duplicates
jscpd --skipLocal# Specify reporters
jscpd --reporters console,html,json
jscpd -r time,console
# Output directory
jscpd --output ./reports
jscpd -o /tmp/jscpd-reports
# Use absolute paths
jscpd --absolute
jscpd -a
# Silent mode (no console output)
jscpd --silent
jscpd -s
# Verbose output
jscpd --verbose
jscpd -v
# Debug mode
jscpd --debug
jscpd -d# Configuration file
jscpd --config .jscpd.json
jscpd -c custom-config.json
# Custom store for large codebases
jscpd --store leveldb
# Git blame integration
jscpd --blame
jscpd -b
# Threshold for exit code
jscpd --threshold 10
jscpd -t 5
# Custom exit code
jscpd --exitCode 2
# Case insensitive (experimental)
jscpd --ignoreCase
# Avoid symlinks
jscpd --noSymlinks
# List supported formats
jscpd --list# Show help
jscpd --help
jscpd -h
# Show version
jscpd --version
jscpd -V
# List all supported formats
jscpd --listJSCPD supports multiple configuration sources with priority order:
.jscpd.json or specified via --config)jscpd property){
"minLines": 5,
"minTokens": 50,
"threshold": 10,
"reporters": ["console", "html"],
"ignore": [
"**/*.test.js",
"**/node_modules/**"
],
"output": "./reports",
"format": [
"javascript",
"typescript"
],
"absolute": true,
"gitignore": true
}{
"name": "my-project",
"jscpd": {
"threshold": 5,
"reporters": ["html"],
"ignore": ["**/*.test.js"]
}
}--exitCode)#!/bin/bash
# CI script example
set -e
echo "Running jscpd analysis..."
jscpd ./src --threshold 5 --reporters console,json --output ./reports
if [ $? -eq 0 ]; then
echo "✅ Code duplication check passed"
else
echo "❌ Code duplication exceeded threshold"
exit 1
fi{
"scripts": {
"jscpd": "jscpd ./src",
"jscpd:ci": "jscpd ./src --threshold 5 --reporters json --output ./reports",
"jscpd:html": "jscpd ./src --reporters html --output ./reports && open ./reports/html/index.html"
}
}