[{"data":1,"prerenderedAt":1281},["ShallowReactive",2],{"navigation_docs":3,"-guides-baseline":249,"-guides-baseline-surround":1272,"page-views-\u002Fguides\u002Fbaseline":1277},[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":45,"body":251,"description":1263,"extension":1264,"links":1265,"meta":1266,"navigation":1267,"path":46,"seo":1268,"stem":47,"__hash__":1271},"docs\u002F2.guides\u002F03.baseline.md",{"type":252,"value":253,"toc":1249},"minimark",[254,258,276,281,294,332,340,452,455,473,484,490,493,497,500,567,574,578,583,605,611,619,625,629,653,659,662,666,678,701,707,730,734,745,760,766,809,813,942,978,982,1067,1071,1211,1219,1223,1245],[255,256,257],"p",{},"Most codebases carry duplication that nobody is going to remove this sprint, and a percentage threshold handles it badly: set high, it lets a fresh copy-paste through under the limit; set low, it trips on legacy code the change never touched. A baseline separates the two. The clones that exist today are recorded and accepted, and a build fails only when a change adds a clone that is not among them. You reach for it when you want a gate on pull requests from day one, on a codebase that is not clean.",[259,260,261,262,266,267,271,272,275],"note",{},"Available from jscpd ",[263,264,265],"strong",{},"5.1.0",". The committed file needs nothing beyond the binary; ",[268,269,270],"code",{},"--baseline-from-ref"," needs ",[268,273,274],{},"git"," and the base ref present in the checkout.",[277,278,280],"h2",{"id":279},"run-it","Run it",[255,282,283,284,293],{},"The commands run on a copy of ",[285,286,290],"a",{"href":287,"rel":288},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\u002Ftree\u002Fmaster\u002Ffixtures\u002Fmcp-demo",[289],"nofollow",[268,291,292],{},"fixtures\u002Fmcp-demo\u002Fsrc",", which holds three exact clones. The first run records them:",[295,296,302],"pre",{"className":297,"code":298,"filename":299,"language":300,"meta":301,"style":301},"language-bash shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","jscpd src --baseline .jscpd-baseline.json --update-baseline --reporters ai\n","Terminal","bash","",[268,303,304],{"__ignoreMap":301},[305,306,309,313,317,320,323,326,329],"span",{"class":307,"line":308},"line",1,[305,310,312],{"class":311},"sBMFI","jscpd",[305,314,316],{"class":315},"sfazB"," src",[305,318,319],{"class":315}," --baseline",[305,321,322],{"class":315}," .jscpd-baseline.json",[305,324,325],{"class":315}," --update-baseline",[305,327,328],{"class":315}," --reporters",[305,330,331],{"class":315}," ai\n",[295,333,338],{"className":334,"code":336,"language":337,"meta":301},[335],"language-text","Baseline .jscpd-baseline.json updated: 3 fingerprints added, 0 removed (3 total)\nClones:\ninvoice.js:1-6 ~ print\u002Finvoice.js:1-6\ninvoice.js:6-12 ~ print\u002Finvoice.js:7-13\norders.js:1-12 ~ reports\u002Forders.js:1-12\n---\n3 clones · 36.2% duplication\n","text",[268,339,336],{"__ignoreMap":301},[295,341,346],{"className":342,"code":343,"filename":344,"language":345,"meta":301,"style":301},"language-json shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","{\n  \"version\": 1,\n  \"fingerprints\": {\n    \"0f6fc236d5d07e6b\": 1,\n    \"de96aa427b11c6eb\": 1,\n    \"eac17f2cc970be19\": 1\n  }\n}\n",".jscpd-baseline.json","json",[268,347,348,354,377,392,409,425,440,446],{"__ignoreMap":301},[305,349,350],{"class":307,"line":308},[305,351,353],{"class":352},"sMK4o","{\n",[305,355,357,360,364,367,370,374],{"class":307,"line":356},2,[305,358,359],{"class":352},"  \"",[305,361,363],{"class":362},"spNyl","version",[305,365,366],{"class":352},"\"",[305,368,369],{"class":352},":",[305,371,373],{"class":372},"sbssI"," 1",[305,375,376],{"class":352},",\n",[305,378,380,382,385,387,389],{"class":307,"line":379},3,[305,381,359],{"class":352},[305,383,384],{"class":362},"fingerprints",[305,386,366],{"class":352},[305,388,369],{"class":352},[305,390,391],{"class":352}," {\n",[305,393,395,398,401,403,405,407],{"class":307,"line":394},4,[305,396,397],{"class":352},"    \"",[305,399,400],{"class":311},"0f6fc236d5d07e6b",[305,402,366],{"class":352},[305,404,369],{"class":352},[305,406,373],{"class":372},[305,408,376],{"class":352},[305,410,412,414,417,419,421,423],{"class":307,"line":411},5,[305,413,397],{"class":352},[305,415,416],{"class":311},"de96aa427b11c6eb",[305,418,366],{"class":352},[305,420,369],{"class":352},[305,422,373],{"class":372},[305,424,376],{"class":352},[305,426,428,430,433,435,437],{"class":307,"line":427},6,[305,429,397],{"class":352},[305,431,432],{"class":311},"eac17f2cc970be19",[305,434,366],{"class":352},[305,436,369],{"class":352},[305,438,439],{"class":372}," 1\n",[305,441,443],{"class":307,"line":442},7,[305,444,445],{"class":352},"  }\n",[305,447,449],{"class":307,"line":448},8,[305,450,451],{"class":352},"}\n",[255,453,454],{},"Commit the file. From now on the gate is one flag:",[295,456,458],{"className":297,"code":457,"filename":299,"language":300,"meta":301,"style":301},"jscpd src --baseline .jscpd-baseline.json --fail-on-new-clones\n",[268,459,460],{"__ignoreMap":301},[305,461,462,464,466,468,470],{"class":307,"line":308},[305,463,312],{"class":311},[305,465,316],{"class":315},[305,467,319],{"class":315},[305,469,322],{"class":315},[305,471,472],{"class":315}," --fail-on-new-clones\n",[255,474,475,476,479,480,483],{},"It prints the three clones without a marker and exits 0. Copy ",[268,477,478],{},"returns.js"," to ",[268,481,482],{},"refunds.js"," and run the same command again:",[295,485,488],{"className":486,"code":487,"language":337,"meta":301},[335],"Clone found (javascript)\n - invoice.js [1:1 - 6:72] (6 lines, 105 tokens)\n   print\u002Finvoice.js [1:1 - 6:72]\nClone found (javascript)\n - invoice.js [6:71 - 12:2] (7 lines, 93 tokens)\n   print\u002Finvoice.js [7:53 - 13:2]\nClone found (javascript)\n - orders.js [1:1 - 12:2] (12 lines, 124 tokens)\n   reports\u002Forders.js [1:1 - 12:2]\nClone found (javascript) [NEW]\n - refunds.js [1:1 - 10:2] (10 lines, 104 tokens)\n   returns.js [1:1 - 10:2]\nFound 4 clones (1 new).\nERROR: jscpd found 1 new clones not in the baseline (allowed: 0)\n",[268,489,487],{"__ignoreMap":301},[255,491,492],{},"The run exits 1. The three old clones are still listed and still count in the percentage; only the fourth fails the build.",[277,494,496],{"id":495},"reading-the-output","Reading the output",[255,498,499],{},"Each key in the baseline file is a hash of a duplicated fragment's content, and the value is how many clones share it. A clone is new when its hash is absent, or when more clones carry it than the file allows, so a third copy of a fragment that has one recorded twin is new. Nothing about paths or line numbers goes into the hash: moving a file, shifting lines above the fragment or switching line endings leaves the gate quiet, and the file diffs one line per fingerprint when you refresh it.",[255,501,502,503,506,507,510,511,513,514,517,518,521,522,525,526,531,532,535,536,539,540,545,546,549,550,553,554,559,560,521,563,566],{},"The console reporters mark a new clone with ",[268,504,505],{},"[NEW]"," and count them in ",[268,508,509],{},"Found 4 clones (1 new)",". The other reporters carry the same information: ",[268,512,345],{}," adds ",[268,515,516],{},"isNew"," to each clone and ",[268,519,520],{},"newClones"," and ",[268,523,524],{},"newDuplicatedLines"," to the totals, ",[285,527,528],{"href":168},[268,529,530],{},"sarif"," reports a new clone at level ",[268,533,534],{},"error"," and the rest at ",[268,537,538],{},"warning",", so GitHub code scanning highlights only the regression, ",[285,541,542],{"href":173},[268,543,544],{},"codeclimate"," gives it severity ",[268,547,548],{},"major"," against ",[268,551,552],{},"minor",", and ",[285,555,556],{"href":178},[268,557,558],{},"openmetrics"," adds the ",[268,561,562],{},"jscpd_new_clones",[268,564,565],{},"jscpd_new_duplicated_lines"," gauges.",[255,568,569,570,573],{},"The percentage in the table counts every clone, old and new, so a ",[268,571,572],{},"--threshold"," in the same run keeps watching the whole picture; when either gate trips, the run exits 1.",[277,575,577],{"id":576},"common-tasks","Common tasks",[579,580,582],"h3",{"id":581},"accept-new-duplication-in-a-pull-request","Accept new duplication in a pull request",[295,584,586],{"className":297,"code":585,"filename":299,"language":300,"meta":301,"style":301},"jscpd src --baseline .jscpd-baseline.json --update-baseline --reporters silent\n",[268,587,588],{"__ignoreMap":301},[305,589,590,592,594,596,598,600,602],{"class":307,"line":308},[305,591,312],{"class":311},[305,593,316],{"class":315},[305,595,319],{"class":315},[305,597,322],{"class":315},[305,599,325],{"class":315},[305,601,328],{"class":315},[305,603,604],{"class":315}," silent\n",[295,606,609],{"className":607,"code":608,"language":337,"meta":301},[335],"Baseline .jscpd-baseline.json updated: 1 fingerprints added, 0 removed (4 total)\nDuplications detection: Found 4 exact clones with 35(44.30%) duplicated lines in 7 (1 formats) files.\n",[268,610,608],{"__ignoreMap":301},[255,612,613,614,521,616,369],{},"Commit the file with the change; the diff shows one added fingerprint, so the reviewer sees that the pull request accepts one more clone. The same command after a refactoring drops what is gone. After deleting ",[268,615,482],{},[268,617,618],{},"reports\u002Forders.js",[295,620,623],{"className":621,"code":622,"language":337,"meta":301},[335],"Baseline .jscpd-baseline.json updated: 0 fingerprints added, 2 removed (2 total)\nDuplications detection: Found 2 exact clones with 13(22.81%) duplicated lines in 5 (1 formats) files.\n",[268,624,622],{"__ignoreMap":301},[579,626,628],{"id":627},"allow-a-budget-of-new-clones","Allow a budget of new clones",[295,630,632],{"className":297,"code":631,"filename":299,"language":300,"meta":301,"style":301},"jscpd src --baseline .jscpd-baseline.json --fail-on-new-clones 1 --reporters ai\n",[268,633,634],{"__ignoreMap":301},[305,635,636,638,640,642,644,647,649,651],{"class":307,"line":308},[305,637,312],{"class":311},[305,639,316],{"class":315},[305,641,319],{"class":315},[305,643,322],{"class":315},[305,645,646],{"class":315}," --fail-on-new-clones",[305,648,373],{"class":372},[305,650,328],{"class":315},[305,652,331],{"class":315},[295,654,657],{"className":655,"code":656,"language":337,"meta":301},[335],"Clones:\ninvoice.js:1-6 ~ print\u002Finvoice.js:1-6\ninvoice.js:6-12 ~ print\u002Finvoice.js:7-13\norders.js:1-12 ~ reports\u002Forders.js:1-12\nrefunds.js:1-10 ~ returns.js:1-10\n---\n4 clones · 44.3% duplication\n",[268,658,656],{"__ignoreMap":301},[255,660,661],{},"The run exits 0: one new clone is within the allowance, a second one would fail. Without a number the allowance is 0.",[579,663,665],{"id":664},"baseline-from-a-git-ref","Baseline from a git ref",[255,667,668,669,671,672,674,675,369],{},"When you would rather keep nothing in the repository, ",[268,670,270],{}," builds the baseline from a git ref's tree: jscpd checks the ref out into a temporary worktree, scans it with the same configuration and compares the two results in memory. On a branch that adds ",[268,673,482],{}," on top of ",[268,676,677],{},"main",[295,679,681],{"className":297,"code":680,"filename":299,"language":300,"meta":301,"style":301},"jscpd src --baseline-from-ref main --fail-on-new-clones --reporters ai\n",[268,682,683],{"__ignoreMap":301},[305,684,685,687,689,692,695,697,699],{"class":307,"line":308},[305,686,312],{"class":311},[305,688,316],{"class":315},[305,690,691],{"class":315}," --baseline-from-ref",[305,693,694],{"class":315}," main",[305,696,646],{"class":315},[305,698,328],{"class":315},[305,700,331],{"class":315},[295,702,705],{"className":703,"code":704,"language":337,"meta":301},[335],"Clones:\ninvoice.js:1-6 ~ print\u002Finvoice.js:1-6\ninvoice.js:6-12 ~ print\u002Finvoice.js:7-13\norders.js:1-12 ~ reports\u002Forders.js:1-12\nrefunds.js:1-10 ~ returns.js:1-10\n---\n4 clones · 44.3% duplication\nERROR: jscpd found 1 new clones not in the baseline (allowed: 0)\n",[268,706,704],{"__ignoreMap":301},[255,708,709,710,713,714,717,718,721,722,725,726,729],{},"The run scans twice, the base tree and the working tree, and the ref has to exist locally. In a shallow CI checkout ",[268,711,712],{},"origin\u002Fmain"," is missing, and jscpd exits 1 with ",[268,715,716],{},"git ref 'origin\u002Fmain' not found"," and the advice to fetch it; ",[268,719,720],{},"git fetch origin main"," followed by ",[268,723,724],{},"--baseline-from-ref FETCH_HEAD"," is the smallest fix, a full fetch the usual one. The flag cannot be combined with ",[268,727,728],{},"--baseline",".",[579,731,733],{"id":732},"only-the-clones-of-the-files-you-changed","Only the clones of the files you changed",[255,735,736,737,740,741,744],{},"From 5.4.1, ",[268,738,739],{},"--changed"," combines a baseline with a filter on the files ",[268,742,743],{},"git status"," lists as changed. Every file is scanned, so a new file that copies an old one is found, and only the clones that touch a changed file are reported:",[295,746,748],{"className":297,"code":747,"filename":299,"language":300,"meta":301,"style":301},"jscpd --changed src\n",[268,749,750],{"__ignoreMap":301},[305,751,752,754,757],{"class":307,"line":308},[305,753,312],{"class":311},[305,755,756],{"class":315}," --changed",[305,758,759],{"class":315}," src\n",[295,761,764],{"className":762,"code":763,"language":337,"meta":301},[335],"Baseline .jscpd-baseline.json saved from HEAD 3f2a9c1: 1 fingerprints\nNo duplicates found.\n",[268,765,763],{"__ignoreMap":301},[255,767,768,769,772,773,775,776,778,779,781,782,784,785,788,789,792,793,796,797,800,801,808],{},"The first run records the clones of ",[268,770,771],{},"HEAD"," in ",[268,774,344],{}," at the repository root, with the commit and a hash of the paths and options, or in the ",[268,777,728],{}," file when you give one. Later runs read it, mark the clones ",[268,780,771],{}," did not have as ",[268,783,505],{},", and count them for ",[268,786,787],{},"--fail-on-new-clones","; after a commit, or with other paths or options, jscpd builds the file again. A baseline file without a commit, such as one ",[268,790,791],{},"--update-baseline"," wrote, is used as it is. ",[268,794,795],{},"--changed-only"," scans the changed files alone, so they match only one another. Both flags are command line only. The ",[285,798,799],{"href":41},"pre-commit guide"," uses them in a hook, and ",[285,802,805],{"href":803,"rel":804},"https:\u002F\u002Fgithub.com\u002Fkucherenko\u002Fjscpd\u002Ftree\u002Fmaster\u002Ffixtures\u002Fchanged-demo",[289],[268,806,807],{},"fixtures\u002Fchanged-demo"," walks through five steps.",[277,810,812],{"id":811},"in-ci","In CI",[295,814,819],{"className":815,"code":816,"filename":817,"language":818,"meta":301,"style":301},"language-yaml shiki shiki-themes material-theme-lighter material-theme material-theme-palenight","on: [pull_request]\n\njobs:\n  jscpd:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: kucherenko\u002Fjscpd@v5\n        with:\n          baseline: .jscpd-baseline.json\n          fail-on-new-clones: true\n          reporters: console,sarif\n",".github\u002Fworkflows\u002Fjscpd.yml","yaml",[268,820,821,838,844,853,860,870,877,890,901,909,920,931],{"__ignoreMap":301},[305,822,823,827,829,832,835],{"class":307,"line":308},[305,824,826],{"class":825},"sfNiH","on",[305,828,369],{"class":352},[305,830,831],{"class":352}," [",[305,833,834],{"class":315},"pull_request",[305,836,837],{"class":352},"]\n",[305,839,840],{"class":307,"line":356},[305,841,843],{"emptyLinePlaceholder":842},true,"\n",[305,845,846,850],{"class":307,"line":379},[305,847,849],{"class":848},"swJcz","jobs",[305,851,852],{"class":352},":\n",[305,854,855,858],{"class":307,"line":394},[305,856,857],{"class":848},"  jscpd",[305,859,852],{"class":352},[305,861,862,865,867],{"class":307,"line":411},[305,863,864],{"class":848},"    runs-on",[305,866,369],{"class":352},[305,868,869],{"class":315}," ubuntu-latest\n",[305,871,872,875],{"class":307,"line":427},[305,873,874],{"class":848},"    steps",[305,876,852],{"class":352},[305,878,879,882,885,887],{"class":307,"line":442},[305,880,881],{"class":352},"      -",[305,883,884],{"class":848}," uses",[305,886,369],{"class":352},[305,888,889],{"class":315}," actions\u002Fcheckout@v4\n",[305,891,892,894,896,898],{"class":307,"line":448},[305,893,881],{"class":352},[305,895,884],{"class":848},[305,897,369],{"class":352},[305,899,900],{"class":315}," kucherenko\u002Fjscpd@v5\n",[305,902,904,907],{"class":307,"line":903},9,[305,905,906],{"class":848},"        with",[305,908,852],{"class":352},[305,910,912,915,917],{"class":307,"line":911},10,[305,913,914],{"class":848},"          baseline",[305,916,369],{"class":352},[305,918,919],{"class":315}," .jscpd-baseline.json\n",[305,921,923,926,928],{"class":307,"line":922},11,[305,924,925],{"class":848},"          fail-on-new-clones",[305,927,369],{"class":352},[305,929,930],{"class":825}," true\n",[305,932,934,937,939],{"class":307,"line":933},12,[305,935,936],{"class":848},"          reporters",[305,938,369],{"class":352},[305,940,941],{"class":315}," console,sarif\n",[255,943,944,947,948,951,952,955,956,959,960,963,964,967,968,971,972,974,975,977],{},[268,945,946],{},"fail-on-new-clones: true"," is the bare flag, an integer is the allowance. For the ref variant, replace ",[268,949,950],{},"baseline"," with ",[268,953,954],{},"baseline-from-ref: origin\u002F${{ github.base_ref }}"," and give ",[268,957,958],{},"actions\u002Fcheckout"," ",[268,961,962],{},"fetch-depth: 0",". On GitLab, the script line is ",[268,965,966],{},"jscpd . --baseline .jscpd-baseline.json --fail-on-new-clones --reporters console,codeclimate,openmetrics",", and the ",[285,969,970],{"href":36},"CI guide"," has the artifacts block around it, so the merge request shows the new clone as a ",[268,973,548],{}," Code Quality issue and the metrics widget shows the ",[268,976,562],{}," delta.",[277,979,981],{"id":980},"limits","Limits",[983,984,985,1004,1017,1028,1055],"ul",{},[986,987,988,989,991,992,995,996,999,1000,1003],"li",{},"Put the paths before ",[268,990,787],{}," or give it a number. The flag takes an optional value, so ",[268,993,994],{},"--fail-on-new-clones src"," reads ",[268,997,998],{},"src"," as the number and exits 2 with ",[268,1001,1002],{},"error: invalid value 'src' for '--fail-on-new-clones [\u003CN>]'",". The GitHub Action orders the arguments itself.",[986,1005,1006,271,1008,1010,1011,1013,1014,1016],{},[268,1007,791],{},[268,1009,728],{}," and exits 1 without it; a ",[268,1012,728],{}," that names a missing file exits 1 and tells you to run with ",[268,1015,791],{}," once.",[986,1018,1019,1020,1023,1024,1027],{},"Record and gate with the same options. The file lists what one run found, so a run with ",[268,1021,1022],{},"--ignore-identifiers"," or ",[268,1025,1026],{},"--max-gap-lines"," added finds clones the file does not know, and they count as new.",[986,1029,1030,521,1033,1036,1037,1039,1040,521,1042,1044,1045,1047,1048,1051,1052,729],{},[268,1031,1032],{},"--dashboard",[268,1034,1035],{},"--health"," do not build a baseline: they warn and ignore ",[268,1038,728],{},", ",[268,1041,270],{},[268,1043,791],{},", and they refuse ",[268,1046,787],{}," with an error. ",[268,1049,1050],{},"--complexity"," never detects clones, so it ignores the whole family with a warning. See the ",[285,1053,1054],{"href":76},"dashboard guide",[986,1056,1057,1059,1060,1062,1063,1066],{},[268,1058,270],{}," runs ",[268,1061,274],{},", so it does not work in the ",[268,1064,1065],{},"ghcr.io\u002Fkucherenko\u002Fjscpd"," image, which holds only the binary.",[277,1068,1070],{"id":1069},"options","Options",[1072,1073,1074,1093],"table",{},[1075,1076,1077],"thead",{},[1078,1079,1080,1084,1087,1090],"tr",{},[1081,1082,1083],"th",{},"Flag",[1081,1085,1086],{},"Config key",[1081,1088,1089],{},"Effect",[1081,1091,1092],{},"Default",[1094,1095,1096,1114,1131,1148,1167,1195],"tbody",{},[1078,1097,1098,1104,1108,1111],{},[1099,1100,1101],"td",{},[268,1102,1103],{},"--baseline \u003CFILE>",[1099,1105,1106],{},[268,1107,950],{},[1099,1109,1110],{},"Read the fingerprints from the file; a clone whose fingerprint is absent is new",[1099,1112,1113],{},"none",[1078,1115,1116,1120,1123,1128],{},[1099,1117,1118],{},[268,1119,791],{},[1099,1121,1122],{},"command line only",[1099,1124,1125,1126],{},"Rewrite the file from this run, create it when missing, print the added and removed counts; needs ",[268,1127,728],{},[1099,1129,1130],{},"off",[1078,1132,1133,1138,1143,1146],{},[1099,1134,1135],{},[268,1136,1137],{},"--fail-on-new-clones [N]",[1099,1139,1140],{},[268,1141,1142],{},"failOnNewClones",[1099,1144,1145],{},"Exit 1 when more than N clones are new; N is 0 without a number; needs one of the two baselines",[1099,1147,1130],{},[1078,1149,1150,1155,1160,1165],{},[1099,1151,1152],{},[268,1153,1154],{},"--baseline-from-ref \u003CREF>",[1099,1156,1157],{},[268,1158,1159],{},"baselineFromRef",[1099,1161,1162,1163],{},"Build the baseline from the ref's tree in a temporary worktree; conflicts with ",[268,1164,728],{},[1099,1166,1113],{},[1078,1168,1169,1173,1175,1193],{},[1099,1170,1171],{},[268,1172,739],{},[1099,1174,1122],{},[1099,1176,1177,1178,1180,1181,1183,1184,1186,1187,1189,1190,1192],{},"Report only the clones of the files ",[268,1179,743],{}," lists as changed, against a baseline of ",[268,1182,771],{}," saved to ",[268,1185,344],{}," or the ",[268,1188,728],{}," file and rebuilt when ",[268,1191,771],{}," moves (5.4.1+)",[1099,1194,1130],{},[1078,1196,1197,1201,1203,1209],{},[1099,1198,1199],{},[268,1200,795],{},[1099,1202,1122],{},[1099,1204,1205,1206,1208],{},"Like ",[268,1207,739],{},", with the changed files scanned alone (5.4.1+)",[1099,1210,1130],{},[255,1212,1213,1215,1216,729],{},[285,1214,130],{"href":131}," lists them with the rest of the flags; the keys go in ",[285,1217,1218],{"href":136},".jscpd.json",[277,1220,1222],{"id":1221},"related","Related",[983,1224,1225,1230,1235,1240],{},[986,1226,1227,1229],{},[285,1228,35],{"href":36}," for the workflows around the gate on GitHub and GitLab.",[986,1231,1232,1234],{},[285,1233,40],{"href":41}," for the same baseline in a hook, so legacy clones do not block commits.",[986,1236,1237,1239],{},[285,1238,70],{"href":71}," for the trend of the number the threshold watches.",[986,1241,1242,1244],{},[285,1243,140],{"href":141}," for every code a gated run can return.",[1246,1247,1248],"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 .sMK4o, html code.shiki .sMK4o{--shiki-light:#39ADB5;--shiki-default:#89DDFF;--shiki-dark:#89DDFF}html pre.shiki code .spNyl, html code.shiki .spNyl{--shiki-light:#9C3EDA;--shiki-default:#C792EA;--shiki-dark:#C792EA}html pre.shiki code .sbssI, html code.shiki .sbssI{--shiki-light:#F76D47;--shiki-default:#F78C6C;--shiki-dark:#F78C6C}html pre.shiki code .sfNiH, html code.shiki .sfNiH{--shiki-light:#FF5370;--shiki-default:#FF9CAC;--shiki-dark:#FF9CAC}html pre.shiki code .swJcz, html code.shiki .swJcz{--shiki-light:#E53935;--shiki-default:#F07178;--shiki-dark:#F07178}",{"title":301,"searchDepth":356,"depth":356,"links":1250},[1251,1252,1253,1259,1260,1261,1262],{"id":279,"depth":356,"text":280},{"id":495,"depth":356,"text":496},{"id":576,"depth":356,"text":577,"children":1254},[1255,1256,1257,1258],{"id":581,"depth":379,"text":582},{"id":627,"depth":379,"text":628},{"id":664,"depth":379,"text":665},{"id":732,"depth":379,"text":733},{"id":811,"depth":356,"text":812},{"id":980,"depth":356,"text":981},{"id":1069,"depth":356,"text":1070},{"id":1221,"depth":356,"text":1222},"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.","md",null,{},{"icon":48},{"title":1269,"description":1270},"Baseline and new-clone gate in jscpd","jscpd --baseline, --update-baseline, --fail-on-new-clones and --baseline-from-ref let a build tolerate the duplication it has and fail only on new clones.","0TpRsfJt5CRjqCFyFoD1-Dq8r4ArSmRg03ttn8gFE5U",[1273,1275],{"title":40,"path":41,"stem":42,"description":1274,"icon":43,"children":-1},"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.",{"title":50,"path":51,"stem":52,"description":1276,"icon":53,"children":-1},"Scan a repository of many packages so the report holds the clones you can act on, with --skip-local and --skip-isolated to drop the pairs you accept.",{"\u002Fguides\u002Fbaseline":1278},{"views":1279,"visits":1280},114,40,1795510270153]