37 lines
1.2 KiB
Markdown
37 lines
1.2 KiB
Markdown
# Quickstart: Copy-Paste Detection Quality Gate
|
|
|
|
## What This Feature Does
|
|
|
|
Adds automated copy-paste detection to the project's quality gates. When a developer commits code, jscpd scans for duplicated code blocks and blocks the commit if duplication exceeds the configured threshold. Developers can also run the scan on-demand.
|
|
|
|
## Key Commands
|
|
|
|
```bash
|
|
# Run copy-paste detection standalone
|
|
pnpm jscpd
|
|
|
|
# Run full quality gate (includes jscpd)
|
|
pnpm check
|
|
|
|
# Commit triggers the check automatically via Lefthook
|
|
git commit -m "my changes"
|
|
```
|
|
|
|
## Configuration
|
|
|
|
The jscpd configuration lives in `.jscpd.json` at the repo root. Key settings:
|
|
|
|
- **threshold**: Max allowed duplication percentage (default: 5%)
|
|
- **minLines**: Minimum lines for a duplicate block (default: 5)
|
|
- **minTokens**: Minimum tokens for a duplicate block (default: 50)
|
|
- **pattern**: File globs to scan (TypeScript/TSX)
|
|
- **ignore**: Directories/files to skip (node_modules, dist, etc.)
|
|
|
|
## How It Integrates
|
|
|
|
```
|
|
git commit → Lefthook pre-commit → pnpm check → knip + biome + tsc + vitest + jscpd
|
|
```
|
|
|
|
The `pnpm check` script is the single merge gate. jscpd is added to this chain, so it automatically runs as part of pre-commit hooks and any CI that uses `pnpm check`.
|