[{"data":1,"prerenderedAt":1331},["ShallowReactive",2],{"navigation_docs":3,"-guides-pre-commit":249,"-guides-pre-commit-surround":1322,"page-views-\u002Fguides\u002Fpre-commit":1327},[4,29,104,124,194],{"title":5,"icon":6,"path":7,"stem":8,"children":9},"Start",false,"\u002Fstart","1.start",[10,14,19,24],{"title":11,"path":7,"stem":12,"icon":13},"What jscpd finds","1.start\u002Findex","i-lucide-house",{"title":15,"path":16,"stem":17,"icon":18},"Installation","\u002Fstart\u002Finstallation","1.start\u002F2.installation","i-lucide-download",{"title":20,"path":21,"stem":22,"icon":23},"Quickstart","\u002Fstart\u002Fquickstart","1.start\u002F3.quickstart","i-lucide-rocket",{"title":25,"path":26,"stem":27,"icon":28},"Configuration basics","\u002Fstart\u002Fconfiguration","1.start\u002F4.configuration","i-lucide-settings-2",{"title":30,"icon":6,"path":31,"stem":32,"children":33,"page":6},"Guides","\u002Fguides","2.guides",[34,39,44,49,54,59,64,69,74,79,84,89,94,99],{"title":35,"path":36,"stem":37,"icon":38},"Use jscpd in CI","\u002Fguides\u002Fci","2.guides\u002F01.ci","i-lucide-github",{"title":40,"path":41,"stem":42,"icon":43},"Pre-commit hooks","\u002Fguides\u002Fpre-commit","2.guides\u002F02.pre-commit","i-lucide-git-commit",{"title":45,"path":46,"stem":47,"icon":48},"Fail only on new duplication","\u002Fguides\u002Fbaseline","2.guides\u002F03.baseline","i-lucide-git-compare",{"title":50,"path":51,"stem":52,"icon":53},"Monorepos","\u002Fguides\u002Fmonorepos","2.guides\u002F04.monorepos","i-lucide-folder-tree",{"title":55,"path":56,"stem":57,"icon":58},"Cross-format detection","\u002Fguides\u002Fcross-format","2.guides\u002F05.cross-format","i-lucide-layers",{"title":60,"path":61,"stem":62,"icon":63},"Agents","\u002Fguides\u002Fagents","2.guides\u002F06.agents","i-lucide-cpu",{"title":65,"path":66,"stem":67,"icon":68},"Editors","\u002Fguides\u002Feditors","2.guides\u002F07.editors","i-lucide-code",{"title":70,"path":71,"stem":72,"icon":73},"Duplication over git history","\u002Fguides\u002Fhistory","2.guides\u002F08.history","i-lucide-chart-no-axes-combined",{"title":75,"path":76,"stem":77,"icon":78},"Dashboard and health score","\u002Fguides\u002Fdashboard","2.guides\u002F09.dashboard","i-lucide-layout-dashboard",{"title":80,"path":81,"stem":82,"icon":83},"Dead code","\u002Fguides\u002Fdead-code","2.guides\u002F10.dead-code","i-lucide-ghost",{"title":85,"path":86,"stem":87,"icon":88},"Comparing two codebases","\u002Fguides\u002Fcompare","2.guides\u002F11.compare","i-lucide-git-compare-arrows",{"title":90,"path":91,"stem":92,"icon":93},"Semantic clones","\u002Fguides\u002Fsemantic-clones","2.guides\u002F12.semantic-clones","i-lucide-brain-circuit",{"title":95,"path":96,"stem":97,"icon":98},"Similar functions","\u002Fguides\u002Fsimilarity","2.guides\u002F13.similarity","i-lucide-list-tree",{"title":100,"path":101,"stem":102,"icon":103},"Boundaries","\u002Fguides\u002Fboundaries","2.guides\u002F14.boundaries","i-lucide-fence",{"title":105,"icon":6,"path":106,"stem":107,"children":108,"page":6},"Concepts","\u002Fconcepts","3.concepts",[109,114,119],{"title":110,"path":111,"stem":112,"icon":113},"Types of code clones","\u002Fconcepts\u002Fclone-types","3.concepts\u002F1.clone-types","i-lucide-copy",{"title":115,"path":116,"stem":117,"icon":118},"How detection works","\u002Fconcepts\u002Fhow-detection-works","3.concepts\u002F2.how-detection-works","i-lucide-scan-search",{"title":120,"path":121,"stem":122,"icon":123},"The health score","\u002Fconcepts\u002Fhealth-score","3.concepts\u002F3.health-score","i-lucide-heart-pulse",{"title":125,"icon":6,"path":126,"stem":127,"children":128,"page":6},"Reference","\u002Freference","4.reference",[129,134,139,144,181,186,190],{"title":130,"path":131,"stem":132,"icon":133},"CLI options","\u002Freference\u002Fcli","4.reference\u002F1.cli","i-lucide-terminal",{"title":135,"path":136,"stem":137,"icon":138},"The config file","\u002Freference\u002Fconfig-file","4.reference\u002F2.config-file","i-lucide-settings",{"title":140,"path":141,"stem":142,"icon":143},"Exit codes","\u002Freference\u002Fexit-codes","4.reference\u002F3.exit-codes","i-lucide-log-out",{"title":145,"icon":6,"path":146,"stem":147,"children":148},"Reporters","\u002Freference\u002Freporters","4.reference\u002F4.reporters\u002Findex",[149,151,156,161,166,171,176],{"title":145,"path":146,"stem":147,"icon":150},"i-lucide-file-chart-column",{"title":152,"path":153,"stem":154,"icon":155},"HTML reporter","\u002Freference\u002Freporters\u002Fhtml","4.reference\u002F4.reporters\u002F2.html","i-lucide-file-code",{"title":157,"path":158,"stem":159,"icon":160},"JSON reporter","\u002Freference\u002Freporters\u002Fjson","4.reference\u002F4.reporters\u002F3.json","i-lucide-braces",{"title":162,"path":163,"stem":164,"icon":165},"Badge reporter","\u002Freference\u002Freporters\u002Fbadge","4.reference\u002F4.reporters\u002F4.badge","i-lucide-award",{"title":167,"path":168,"stem":169,"icon":170},"SARIF reporter","\u002Freference\u002Freporters\u002Fsarif","4.reference\u002F4.reporters\u002F5.sarif","i-lucide-shield-check",{"title":172,"path":173,"stem":174,"icon":175},"CodeClimate reporter","\u002Freference\u002Freporters\u002Fcodeclimate","4.reference\u002F4.reporters\u002F6.codeclimate","i-lucide-flag-triangle-right",{"title":177,"path":178,"stem":179,"icon":180},"OpenMetrics reporter","\u002Freference\u002Freporters\u002Fopenmetrics","4.reference\u002F4.reporters\u002F7.openmetrics","i-lucide-activity",{"title":182,"path":183,"stem":184,"icon":185},"Supported formats","\u002Freference\u002Fsupported-formats","4.reference\u002F5.supported-formats","i-lucide-languages",{"title":187,"path":188,"stem":189,"icon":38},"GitHub Action","\u002Freference\u002Fgithub-action","4.reference\u002F6.github-action",{"title":191,"path":192,"stem":193,"icon":68},"Rust crates","\u002Freference\u002Frust-crates","4.reference\u002F7.rust-crates",{"title":195,"icon":6,"path":196,"stem":197,"children":198,"page":6},"Project","\u002Fproject","5.project",[199,204,209,214,239,244],{"title":200,"path":201,"stem":202,"icon":203},"Changelog","\u002Fproject\u002Fchangelog","5.project\u002F1.changelog","i-lucide-scroll-text",{"title":205,"path":206,"stem":207,"icon":208},"Migrating from v4 to v5","\u002Fproject\u002Fmigration","5.project\u002F2.migration","i-lucide-arrow-right-left",{"title":210,"path":211,"stem":212,"icon":213},"jscpd v4 (TypeScript)","\u002Fproject\u002Fv4","5.project\u002F3.v4","i-simple-icons-typescript",{"title":215,"icon":6,"path":216,"stem":217,"children":218},"Benchmarks","\u002Fproject\u002Fbenchmarks","5.project\u002F4.benchmarks\u002Findex",[219,221,226,230,235],{"title":215,"path":216,"stem":217,"icon":220},"i-lucide-gauge",{"title":222,"path":223,"stem":224,"icon":225},"Detection Speed","\u002Fproject\u002Fbenchmarks\u002Fdetection-speed","5.project\u002F4.benchmarks\u002F2.detection-speed","i-lucide-zap",{"title":227,"path":228,"stem":229,"icon":58},"Multi-Format Detection","\u002Fproject\u002Fbenchmarks\u002Fcross-format","5.project\u002F4.benchmarks\u002F3.cross-format",{"title":231,"path":232,"stem":233,"icon":234},"AI Token Efficiency","\u002Fproject\u002Fbenchmarks\u002Fai-token-efficiency","5.project\u002F4.benchmarks\u002F4.ai-token-efficiency","i-lucide-sparkles",{"title":236,"path":237,"stem":238,"icon":93},"Embedding Models","\u002Fproject\u002Fbenchmarks\u002Fembedding-models","5.project\u002F4.benchmarks\u002F5.embedding-models",{"title":240,"path":241,"stem":242,"icon":243},"Research","\u002Fproject\u002Fresearch","5.project\u002F5.research","i-lucide-graduation-cap",{"title":245,"path":246,"stem":247,"icon":248},"Articles","\u002Fproject\u002Farticles","5.project\u002F6.articles","i-lucide-newspaper",{"id":250,"title":40,"body":251,"description":1313,"extension":1314,"links":1315,"meta":1316,"navigation":1317,"path":41,"seo":1318,"stem":42,"__hash__":1321},"docs\u002F2.guides\u002F02.pre-commit.md",{"type":252,"value":253,"toc":1289},"minimark",[254,275,280,284,356,381,398,422,430,441,445,466,481,505,534,538,561,577,596,632,636,640,759,814,818,919,950,954,1004,1014,1018,1087,1115,1118,1145,1149,1153,1165,1171,1184,1188,1197,1201,1223,1229,1242,1246,1256,1260,1285],[255,256,257,258,262,263,270,271,274],"p",{},"A hook runs jscpd on the developer's machine at ",[259,260,261],"code",{},"git commit",", before the change reaches a branch anyone else sees. It is the earliest gate and the cheapest one: no runner, no checkout, a scan that takes milliseconds, and the commit goes through or it does not. This page sets the hook up with the ",[264,265,269],"a",{"href":266,"rel":267},"https:\u002F\u002Fpre-commit.com",[268],"nofollow","pre-commit framework",", with Husky and with a plain git hook, then shows how to keep it from blocking on duplication that was already there. The shared gate for pull requests is on the ",[264,272,273],{"href":36},"CI page",".",[276,277,279],"h2",{"id":278},"minimal-setup","Minimal setup",[281,282,269],"h3",{"id":283},"pre-commit-framework",[285,286,292],"pre",{"className":287,"code":288,"filename":289,"language":290,"meta":291,"style":291},"language-yaml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","repos:\n  - repo: https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\n    rev: v5.4.3\n    hooks:\n      - id: jscpd\n",".pre-commit-config.yaml","yaml","",[259,293,294,307,323,334,342],{"__ignoreMap":291},[295,296,299,303],"span",{"class":297,"line":298},"line",1,[295,300,302],{"class":301},"swJcz","repos",[295,304,306],{"class":305},"sMK4o",":\n",[295,308,310,313,316,319],{"class":297,"line":309},2,[295,311,312],{"class":305},"  -",[295,314,315],{"class":301}," repo",[295,317,318],{"class":305},":",[295,320,322],{"class":321},"sfazB"," https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\n",[295,324,326,329,331],{"class":297,"line":325},3,[295,327,328],{"class":301},"    rev",[295,330,318],{"class":305},[295,332,333],{"class":321}," v5.4.3\n",[295,335,337,340],{"class":297,"line":336},4,[295,338,339],{"class":301},"    hooks",[295,341,306],{"class":305},[295,343,345,348,351,353],{"class":297,"line":344},5,[295,346,347],{"class":305},"      -",[295,349,350],{"class":301}," id",[295,352,318],{"class":305},[295,354,355],{"class":321}," jscpd\n",[255,357,358,359,362,363,366,367,372,373,376,377,380],{},"The hook is defined in the jscpd repository: on every commit it runs ",[259,360,361],{},"jscpd --exit-code 1"," on the staged text files and blocks the commit when two of them hold a clone. Since jscpd 5.2.1 it is a ",[259,364,365],{},"language: python"," hook that installs the ",[264,368,371],{"href":369,"rel":370},"https:\u002F\u002Fpypi.org\u002Fproject\u002Fjscpd\u002F",[268],"PyPI wheel"," of the pinned release into pre-commit's own environment, so the machine needs no Node.js; ",[259,374,375],{},"pre-commit autoupdate"," moves ",[259,378,379],{},"rev"," to the latest tag.",[285,382,387],{"className":383,"code":384,"filename":385,"language":386,"meta":291,"style":291},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","pre-commit install\n","Terminal","bash",[259,388,389],{"__ignoreMap":291},[295,390,391,395],{"class":297,"line":298},[295,392,394],{"class":393},"sBMFI","pre-commit",[295,396,397],{"class":321}," install\n",[285,399,401],{"className":383,"code":400,"filename":385,"language":386,"meta":291,"style":291},"pre-commit run jscpd --files src\u002Forders.js src\u002Freports\u002Forders.js\n",[259,402,403],{"__ignoreMap":291},[295,404,405,407,410,413,416,419],{"class":297,"line":298},[295,406,394],{"class":393},[295,408,409],{"class":321}," run",[295,411,412],{"class":321}," jscpd",[295,414,415],{"class":321}," --files",[295,417,418],{"class":321}," src\u002Forders.js",[295,420,421],{"class":321}," src\u002Freports\u002Forders.js\n",[285,423,428],{"className":424,"code":426,"language":427,"meta":291},[425],"language-text","Check for duplicated code................................................Failed\n- hook id: jscpd\n- exit code: 1\n\nClone found (javascript)\n - orders.js [1:1 - 12:2] (12 lines, 124 tokens)\n   reports\u002Forders.js [1:1 - 12:2]\nFound 1 clones.\n","text",[259,429,426],{"__ignoreMap":291},[255,431,432,433,440],{},"The two files are the exact pair of ",[264,434,437],{"href":435,"rel":436},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\u002Ftree\u002Fmaster\u002Ffixtures\u002Fmcp-demo",[268],[259,438,439],{},"fixtures\u002Fmcp-demo","; a staged file whose twin is not staged passes, because the hook sees the staged files only.",[281,442,444],{"id":443},"husky","Husky",[285,446,448],{"className":383,"code":447,"filename":385,"language":386,"meta":291,"style":291},"npm install -D husky jscpd\n",[259,449,450],{"__ignoreMap":291},[295,451,452,455,458,461,464],{"class":297,"line":298},[295,453,454],{"class":393},"npm",[295,456,457],{"class":321}," install",[295,459,460],{"class":321}," -D",[295,462,463],{"class":321}," husky",[295,465,355],{"class":321},[285,467,469],{"className":383,"code":468,"filename":385,"language":386,"meta":291,"style":291},"npx husky init\n",[259,470,471],{"__ignoreMap":291},[295,472,473,476,478],{"class":297,"line":298},[295,474,475],{"class":393},"npx",[295,477,463],{"class":321},[295,479,480],{"class":321}," init\n",[285,482,487],{"className":483,"code":484,"filename":485,"language":486,"meta":291,"style":291},"language-sh shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","npx jscpd . --threshold 5\n",".husky\u002Fpre-commit","sh",[259,488,489],{"__ignoreMap":291},[295,490,491,493,495,498,501],{"class":297,"line":298},[295,492,475],{"class":393},[295,494,412],{"class":321},[295,496,497],{"class":321}," .",[295,499,500],{"class":321}," --threshold",[295,502,504],{"class":503},"sbssI"," 5\n",[255,506,507,510,511,513,514,517,518,521,522,525,526,529,530,533],{},[259,508,509],{},"husky init"," creates ",[259,512,485],{}," with ",[259,515,516],{},"npm test"," in it and adds a ",[259,519,520],{},"prepare"," script, so every ",[259,523,524],{},"npm install"," wires the hook; replace the file's content with the jscpd command. With jscpd in ",[259,527,528],{},"devDependencies"," the hook runs the version from the lockfile; ",[259,531,532],{},"npx jscpd@5"," works without the install and downloads the package on its first run.",[281,535,537],{"id":536},"a-plain-git-hook","A plain git hook",[285,539,542],{"className":483,"code":540,"filename":541,"language":486,"meta":291,"style":291},"#!\u002Fbin\u002Fsh\njscpd . --threshold 5\n",".githooks\u002Fpre-commit",[259,543,544,550],{"__ignoreMap":291},[295,545,546],{"class":297,"line":298},[295,547,549],{"class":548},"sHwdD","#!\u002Fbin\u002Fsh\n",[295,551,552,555,557,559],{"class":297,"line":309},[295,553,554],{"class":393},"jscpd",[295,556,497],{"class":321},[295,558,500],{"class":321},[295,560,504],{"class":503},[285,562,564],{"className":383,"code":563,"filename":385,"language":386,"meta":291,"style":291},"chmod +x .githooks\u002Fpre-commit\n",[259,565,566],{"__ignoreMap":291},[295,567,568,571,574],{"class":297,"line":298},[295,569,570],{"class":393},"chmod",[295,572,573],{"class":321}," +x",[295,575,576],{"class":321}," .githooks\u002Fpre-commit\n",[285,578,580],{"className":383,"code":579,"filename":385,"language":386,"meta":291,"style":291},"git config core.hooksPath .githooks\n",[259,581,582],{"__ignoreMap":291},[295,583,584,587,590,593],{"class":297,"line":298},[295,585,586],{"class":393},"git",[295,588,589],{"class":321}," config",[295,591,592],{"class":321}," core.hooksPath",[295,594,595],{"class":321}," .githooks\n",[255,597,598,599,602,603,606,607,609,610,613,614,617,618,620,621,624,625,628,629,274],{},"Hooks under ",[259,600,601],{},".git\u002Fhooks"," are not versioned, so the script lives in the repository and git is pointed at the directory; each clone of the repository runs the ",[259,604,605],{},"git config"," command once, from a ",[259,608,520],{}," script in ",[259,611,612],{},"package.json",", a ",[259,615,616],{},"make hooks"," target or the onboarding notes. This hook runs whatever ",[259,619,554],{}," is on the PATH: ",[259,622,623],{},"npm install -g jscpd@5",", ",[259,626,627],{},"pip install jscpd"," or the installer from the ",[264,630,631],{"href":16},"installation page",[276,633,635],{"id":634},"make-it-useful","Make it useful",[281,637,639],{"id":638},"report-only-the-clones-of-the-files-you-are-committing","Report only the clones of the files you are committing",[285,641,643],{"className":287,"code":642,"filename":289,"language":290,"meta":291,"style":291},"repos:\n  - repo: https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\n    rev: v5.4.3\n    hooks:\n      - id: jscpd\n        pass_filenames: false\n        always_run: true\n        args: [\"src\", \"--changed\", \"--fail-on-new-clones\", \"0\"]\n",[259,644,645,651,661,669,675,685,697,708],{"__ignoreMap":291},[295,646,647,649],{"class":297,"line":298},[295,648,302],{"class":301},[295,650,306],{"class":305},[295,652,653,655,657,659],{"class":297,"line":309},[295,654,312],{"class":305},[295,656,315],{"class":301},[295,658,318],{"class":305},[295,660,322],{"class":321},[295,662,663,665,667],{"class":297,"line":325},[295,664,328],{"class":301},[295,666,318],{"class":305},[295,668,333],{"class":321},[295,670,671,673],{"class":297,"line":336},[295,672,339],{"class":301},[295,674,306],{"class":305},[295,676,677,679,681,683],{"class":297,"line":344},[295,678,347],{"class":305},[295,680,350],{"class":301},[295,682,318],{"class":305},[295,684,355],{"class":321},[295,686,688,691,693],{"class":297,"line":687},6,[295,689,690],{"class":301},"        pass_filenames",[295,692,318],{"class":305},[295,694,696],{"class":695},"sfNiH"," false\n",[295,698,700,703,705],{"class":297,"line":699},7,[295,701,702],{"class":301},"        always_run",[295,704,318],{"class":305},[295,706,707],{"class":695}," true\n",[295,709,711,714,716,719,722,725,727,730,733,736,738,740,742,745,747,749,751,754,756],{"class":297,"line":710},8,[295,712,713],{"class":301},"        args",[295,715,318],{"class":305},[295,717,718],{"class":305}," [",[295,720,721],{"class":305},"\"",[295,723,724],{"class":321},"src",[295,726,721],{"class":305},[295,728,729],{"class":305},",",[295,731,732],{"class":305}," \"",[295,734,735],{"class":321},"--changed",[295,737,721],{"class":305},[295,739,729],{"class":305},[295,741,732],{"class":305},[295,743,744],{"class":321},"--fail-on-new-clones",[295,746,721],{"class":305},[295,748,729],{"class":305},[295,750,732],{"class":305},[295,752,753],{"class":321},"0",[295,755,721],{"class":305},[295,757,758],{"class":305},"]\n",[255,760,761,762,764,765,768,769,771,772,775,776,779,780,783,784,786,787,790,791,794,795,798,799,801,802,805,806,813],{},"From 5.4.1, ",[259,763,735],{}," keeps the clones that touch a file ",[259,766,767],{},"git status"," lists as changed: staged, unstaged and untracked files, a renamed file under its new name. jscpd still scans all of ",[259,770,724],{},", so a staged file that copies a file nobody touched is reported, with the copy's lines. The first run saves the clones of ",[259,773,774],{},"HEAD"," to ",[259,777,778],{},".jscpd-baseline.json"," at the repository root, or to the ",[259,781,782],{},"--baseline"," file, and builds it again after a commit; the clones ",[259,785,774],{}," did not have carry a ",[259,788,789],{},"[NEW]"," marker, and ",[259,792,793],{},"--fail-on-new-clones 0"," fails the commit on them while a clone that was already there goes through. Add the file to ",[259,796,797],{},".gitignore"," unless you want to commit it, jscpd rebuilds it when ",[259,800,774],{}," moves. ",[259,803,804],{},"--changed-only"," scans the changed files alone and compares them only with one another, which is faster and misses the copy of an unchanged file. Both flags are command line only; ",[264,807,810],{"href":808,"rel":809},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\u002Ftree\u002Fmaster\u002Ffixtures\u002Fchanged-demo",[268],[259,811,812],{},"fixtures\u002Fchanged-demo"," walks through five commits.",[281,815,817],{"id":816},"scan-the-whole-tree-and-let-legacy-clones-through","Scan the whole tree and let legacy clones through",[285,819,821],{"className":287,"code":820,"filename":289,"language":290,"meta":291,"style":291},"repos:\n  - repo: https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\n    rev: v5.4.3\n    hooks:\n      - id: jscpd\n        pass_filenames: false\n        always_run: true\n        args: [\"src\", \"--baseline\", \".jscpd-baseline.json\", \"--fail-on-new-clones\"]\n",[259,822,823,829,839,847,853,863,871,879],{"__ignoreMap":291},[295,824,825,827],{"class":297,"line":298},[295,826,302],{"class":301},[295,828,306],{"class":305},[295,830,831,833,835,837],{"class":297,"line":309},[295,832,312],{"class":305},[295,834,315],{"class":301},[295,836,318],{"class":305},[295,838,322],{"class":321},[295,840,841,843,845],{"class":297,"line":325},[295,842,328],{"class":301},[295,844,318],{"class":305},[295,846,333],{"class":321},[295,848,849,851],{"class":297,"line":336},[295,850,339],{"class":301},[295,852,306],{"class":305},[295,854,855,857,859,861],{"class":297,"line":344},[295,856,347],{"class":305},[295,858,350],{"class":301},[295,860,318],{"class":305},[295,862,355],{"class":321},[295,864,865,867,869],{"class":297,"line":687},[295,866,690],{"class":301},[295,868,318],{"class":305},[295,870,696],{"class":695},[295,872,873,875,877],{"class":297,"line":699},[295,874,702],{"class":301},[295,876,318],{"class":305},[295,878,707],{"class":695},[295,880,881,883,885,887,889,891,893,895,897,899,901,903,905,907,909,911,913,915,917],{"class":297,"line":710},[295,882,713],{"class":301},[295,884,318],{"class":305},[295,886,718],{"class":305},[295,888,721],{"class":305},[295,890,724],{"class":321},[295,892,721],{"class":305},[295,894,729],{"class":305},[295,896,732],{"class":305},[295,898,782],{"class":321},[295,900,721],{"class":305},[295,902,729],{"class":305},[295,904,732],{"class":305},[295,906,778],{"class":321},[295,908,721],{"class":305},[295,910,729],{"class":305},[295,912,732],{"class":305},[295,914,744],{"class":321},[295,916,721],{"class":305},[295,918,758],{"class":305},[255,920,921,924,925,928,929,931,932,934,935,937,938,941,942,945,946,949],{},[259,922,923],{},"pass_filenames: false"," stops pre-commit from handing the staged files to jscpd and ",[259,926,927],{},"always_run: true"," runs the hook even when no staged file is code, so jscpd scans ",[259,930,724],{}," as a whole and sees a clone between a staged file and one nobody touched. The baseline lets the clones recorded in ",[259,933,778],{}," through and fails the commit on a new one, with a ",[259,936,789],{}," marker on the pair; ",[259,939,940],{},"args"," replaces the hook's own ",[259,943,944],{},"--exit-code 1",", so the gate is what you put there. The ",[264,947,948],{"href":46},"baseline guide"," shows how to record and refresh the file.",[281,951,953],{"id":952},"gate-on-a-percentage","Gate on a percentage",[285,955,957],{"className":287,"code":956,"filename":289,"language":290,"meta":291,"style":291},"      - id: jscpd\n        require_serial: true\n        args: [\"--threshold\", \"5\"]\n",[259,958,959,969,978],{"__ignoreMap":291},[295,960,961,963,965,967],{"class":297,"line":298},[295,962,347],{"class":305},[295,964,350],{"class":301},[295,966,318],{"class":305},[295,968,355],{"class":321},[295,970,971,974,976],{"class":297,"line":309},[295,972,973],{"class":301},"        require_serial",[295,975,318],{"class":305},[295,977,707],{"class":695},[295,979,980,982,984,986,988,991,993,995,997,1000,1002],{"class":297,"line":325},[295,981,713],{"class":301},[295,983,318],{"class":305},[295,985,718],{"class":305},[295,987,721],{"class":305},[295,989,990],{"class":321},"--threshold",[295,992,721],{"class":305},[295,994,729],{"class":305},[295,996,732],{"class":305},[295,998,999],{"class":321},"5",[295,1001,721],{"class":305},[295,1003,758],{"class":305},[255,1005,1006,1007,1009,1010,1013],{},"With ",[259,1008,940],{}," set this way, the staged files still follow at the end of the command line, and the hook fails when their duplication is above 5 percent (strictly greater), which lets a small clone among large files through. ",[259,1011,1012],{},"require_serial: true"," keeps all staged files in one jscpd process; without it pre-commit splits them over several processes, and a pair can be split with them.",[281,1015,1017],{"id":1016},"scope-the-hook","Scope the hook",[285,1019,1021],{"className":287,"code":1020,"filename":289,"language":290,"meta":291,"style":291},"      - id: jscpd\n        files: \\.(ts|tsx)$\n        args: [\"--exit-code\", \"1\", \"--ignore\", \"**\u002F__snapshots__\u002F**\"]\n",[259,1022,1023,1033,1043],{"__ignoreMap":291},[295,1024,1025,1027,1029,1031],{"class":297,"line":298},[295,1026,347],{"class":305},[295,1028,350],{"class":301},[295,1030,318],{"class":305},[295,1032,355],{"class":321},[295,1034,1035,1038,1040],{"class":297,"line":309},[295,1036,1037],{"class":301},"        files",[295,1039,318],{"class":305},[295,1041,1042],{"class":321}," \\.(ts|tsx)$\n",[295,1044,1045,1047,1049,1051,1053,1056,1058,1060,1062,1065,1067,1069,1071,1074,1076,1078,1080,1083,1085],{"class":297,"line":325},[295,1046,713],{"class":301},[295,1048,318],{"class":305},[295,1050,718],{"class":305},[295,1052,721],{"class":305},[295,1054,1055],{"class":321},"--exit-code",[295,1057,721],{"class":305},[295,1059,729],{"class":305},[295,1061,732],{"class":305},[295,1063,1064],{"class":321},"1",[295,1066,721],{"class":305},[295,1068,729],{"class":305},[295,1070,732],{"class":305},[295,1072,1073],{"class":321},"--ignore",[295,1075,721],{"class":305},[295,1077,729],{"class":305},[295,1079,732],{"class":305},[295,1081,1082],{"class":321},"**\u002F__snapshots__\u002F**",[295,1084,721],{"class":305},[295,1086,758],{"class":305},[255,1088,1089,1090,1093,1094,1097,1098,1101,1102,1093,1105,1107,1108,1110,1111,1114],{},"pre-commit's ",[259,1091,1092],{},"files"," and ",[259,1095,1096],{},"exclude"," patterns decide which staged files reach the hook (it declares ",[259,1099,1100],{},"types: [text]",", so every text file does by default), and jscpd's ",[259,1103,1104],{},"--format",[259,1106,1073],{}," filter again inside the run; a file outside the ",[259,1109,1104],{}," list is left out even when pre-commit passes it. The format names are on the ",[264,1112,1113],{"href":183},"supported formats"," page.",[276,1116,125],{"id":1117},"reference",[1119,1120,1121,1130,1135],"ul",{},[1122,1123,1124,1126,1127,1129],"li",{},[264,1125,130],{"href":131}," for every flag the ",[259,1128,940],{}," list can take.",[1122,1131,1132,1134],{},[264,1133,140],{"href":141}," for what makes the hook fail.",[1122,1136,1137,1140,1141,1144],{},[264,1138,1139],{"href":136},"Configuration file",", since a ",[259,1142,1143],{},".jscpd.json"," in the repository root applies to the hook too: git runs hooks from the root of the working tree.",[276,1146,1148],{"id":1147},"troubleshooting","Troubleshooting",[281,1150,1152],{"id":1151},"the-hook-passes-although-two-staged-files-are-clones","The hook passes although two staged files are clones",[255,1154,1155,1156,1158,1159,1161,1162,1164],{},"pre-commit spreads the staged files over several jscpd processes, one per CPU core, so the two files of a pair can land in different batches and no process sees both; the output then holds two statistics tables. Set ",[259,1157,1012],{}," on the hook to keep the files in one process, or scan the tree with ",[259,1160,923],{}," as above, with ",[259,1163,735],{}," to see only the clones of the staged files.",[281,1166,1168],{"id":1167},"error-invalid-value-srcordersjs-for-exit-code-exit_code",[259,1169,1170],{},"error: invalid value 'src\u002Forders.js' for '--exit-code [\u003CEXIT_CODE>]'",[255,1172,1173,1093,1175,1177,1178,1180,1181,1183],{},[259,1174,1055],{},[259,1176,744],{}," take an optional number, so a file name right after them is read as that number and jscpd exits 2. Always give the number in a hook, ",[259,1179,944],{}," or ",[259,1182,793],{},", because pre-commit appends the file names at the end of the command line.",[281,1185,1187],{"id":1186},"the-commit-is-blocked-by-duplication-that-was-already-there","The commit is blocked by duplication that was already there",[255,1189,1190,1192,1193,775,1195,274],{},[259,1191,944],{}," fails on any clone among the files it sees, old or new. Record the accepted state in a baseline and gate on new clones only, as above, or switch the ",[259,1194,940],{},[259,1196,990],{},[281,1198,1200],{"id":1199},"the-table-lists-bash-and-perl-files-the-project-does-not-have","The table lists bash and perl files the project does not have",[255,1202,1203,1204,1206,1207,1210,1211,1213,1214,1216,1217,1219,1220,274],{},"A scan of the repository root (",[259,1205,274],{},") walks ",[259,1208,1209],{},".git"," as well, and the sample hooks in ",[259,1212,601],{}," count as shell and Perl sources. Pass the source directories (",[259,1215,724],{},") instead of ",[259,1218,274],{},", or add ",[259,1221,1222],{},"--ignore \"**\u002F.git\u002F**\"",[281,1224,1226,1227],{"id":1225},"nodejs-errors-with-an-older-rev","Node.js errors with an older ",[259,1228,379],{},[255,1230,1231,1232,1235,1236,1238,1239,1241],{},"Up to v5.2.0 the hook was ",[259,1233,1234],{},"language: node"," and needed Node.js; from v5.2.1 it installs the PyPI wheel. Move ",[259,1237,379],{}," forward. The Husky and plain hooks run whatever ",[259,1240,554],{}," the PATH resolves, so install it where the hook runs.",[281,1243,1245],{"id":1244},"skipping-the-hook-once","Skipping the hook once",[255,1247,1248,1251,1252,1255],{},[259,1249,1250],{},"SKIP=jscpd git commit"," skips this hook in the pre-commit framework; ",[259,1253,1254],{},"git commit --no-verify"," skips every hook of any kind.",[276,1257,1259],{"id":1258},"related","Related",[1119,1261,1262,1267,1272,1277],{},[1122,1263,1264,1266],{},[264,1265,35],{"href":36}," for the shared gate that a skipped hook cannot bypass.",[1122,1268,1269,1271],{},[264,1270,45],{"href":46}," for the baseline the whole-tree hook relies on.",[1122,1273,1274,1276],{},[264,1275,140],{"href":141}," for the codes a hook turns into a blocked commit.",[1122,1278,1279,1281,1282,1284],{},[264,1280,15],{"href":16}," for every way to put ",[259,1283,554],{}," on the PATH.",[1286,1287,1288],"style",{},"html pre.shiki code .sBMFI, html code.shiki .sBMFI{--shiki-light:#E2931D;--shiki-default:#FFCB6B;--shiki-dark:#FFCB6B}html pre.shiki code .sfazB, html code.shiki .sfazB{--shiki-light:#91B859;--shiki-default:#C3E88D;--shiki-dark:#C3E88D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sHwdD, html code.shiki .sHwdD{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#546E7A;--shiki-default-font-style:italic;--shiki-dark:#676E95;--shiki-dark-font-style:italic}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}html pre.shiki code .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}",{"title":291,"searchDepth":309,"depth":309,"links":1290},[1291,1296,1302,1303,1312],{"id":278,"depth":309,"text":279,"children":1292},[1293,1294,1295],{"id":283,"depth":325,"text":269},{"id":443,"depth":325,"text":444},{"id":536,"depth":325,"text":537},{"id":634,"depth":309,"text":635,"children":1297},[1298,1299,1300,1301],{"id":638,"depth":325,"text":639},{"id":816,"depth":325,"text":817},{"id":952,"depth":325,"text":953},{"id":1016,"depth":325,"text":1017},{"id":1117,"depth":309,"text":125},{"id":1147,"depth":309,"text":1148,"children":1304},[1305,1306,1307,1308,1309,1311],{"id":1151,"depth":325,"text":1152},{"id":1167,"depth":325,"text":1170},{"id":1186,"depth":325,"text":1187},{"id":1199,"depth":325,"text":1200},{"id":1225,"depth":325,"text":1310},"Node.js errors with an older rev",{"id":1244,"depth":325,"text":1245},{"id":1258,"depth":309,"text":1259},"Run jscpd at git commit with the pre-commit framework, Husky or a plain git hook, so a copy-paste is caught before it leaves the machine.","md",null,{},{"icon":43},{"title":1319,"description":1320},"jscpd as a pre-commit hook","Block a commit that adds duplicated code with the jscpd hook for the pre-commit framework, a Husky hook or a plain git hook, and tune what the hook scans.","udsfTjWZ9hphqQRu0z-HTfyYA8JAhELq1NnUJL088bw",[1323,1325],{"title":35,"path":36,"stem":37,"description":1324,"icon":38,"children":-1},"Run jscpd as a failing check on GitHub Actions, GitLab CI or any other runner, with SARIF, Code Quality and metrics reports.",{"title":45,"path":46,"stem":47,"description":1326,"icon":48,"children":-1},"Record the clones a codebase already has in a baseline file or take them from a git ref, and fail the build only when a change adds a clone.",{"\u002Fguides\u002Fpre-commit":1328},{"views":1329,"visits":1330},144,29,1795510270032]