Skip to content

Commit 7dabb7c

Browse files
ci(lint): run jscpd in CI, compare to static threshold. (#5833)
## Problem New contributors often copy-paste logic and test cases, which creates a maintenance cost for little gain. Examples - #3837 (comment) - #3805 (comment) We call these repeated segments of code "clones". ## Solution implement a static threshold. Run `jscpd` in CI and compare the % duplicated to a fixed threshold of 1.34%, which is the current duplication rate in the repo. The main issue with this solution is that it fails to provide easy debugging options when new duplicates are found. Currently exploring adding this functionality in a follow-up. #### Notes - this is a summary of the problem/solution. For full information, see full doc (VSCode: Detecting and Reducing Duplicate Code) describing changes. --- <!--- REMINDER: Ensure that your PR meets the guidelines in CONTRIBUTING.md --> License: I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Justin M. Keyes <[email protected]>
1 parent 800f536 commit 7dabb7c

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

.github/workflows/jscpd.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"pattern": "packages/**/*.ts",
3+
"ignore": ["**node_modules**", "**dist**"],
4+
"gitignore": true,
5+
"threshold": 1.34,
6+
"minLines": 15
7+
}

.github/workflows/node.js.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,24 @@ jobs:
5555
- run: npm run testCompile
5656
- run: npm run lint
5757

58+
jscpd:
59+
needs: lint-commits
60+
runs-on: ubuntu-latest
61+
strategy:
62+
matrix:
63+
node-version: [18.x]
64+
env:
65+
NODE_OPTIONS: '--max-old-space-size=8192'
66+
steps:
67+
- uses: actions/checkout@v4
68+
- name: Use Node.js ${{ matrix.node-version }}
69+
uses: actions/setup-node@v4
70+
with:
71+
node-version: ${{ matrix.node-version }}
72+
- run: npm install jscpd
73+
- name: Run jscpd
74+
run: npx jscpd --config "$GITHUB_WORKSPACE/.github/workflows/jscpd.json"
75+
5876
macos:
5977
needs: lint-commits
6078
name: test macOS

0 commit comments

Comments
 (0)