-
Notifications
You must be signed in to change notification settings - Fork 472
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ci(lint): expand jscpd to use branch comparison #5862
Conversation
This pull request modifies code in src/ but no tests were added/updated. Confirm whether tests should be added or ensure the PR description explains why tests are not required. |
cdd71ac
to
ca3c3ec
Compare
@@ -1,7 +1,9 @@ | |||
{ | |||
"pattern": "packages/**/*.ts", | |||
"ignore": ["**node_modules**", "**dist**"], | |||
"ignore": ["**node_modules**", "**dist**", "*/scripts/*"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be **/scripts/**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, verified you are correct. Here's the followup: #5930
Problem
Follow up to: #5833
A static threshold is useful, but if the threshold fails, we want to be able to see what the new duplicated code is.
Solution
Run
jscpd
on the current branch, and if it is above the set threshold, we fail (same as before).Now, we also filter the resulting report to contain only clones from the files changed with respect to the base branch. Then, if the filtered report is non-empty, i.e. one of the changed files has a clone, fail and display the clones in CI.
Adding this extra step allows us to know when we are adding a clone that was not otherwise in the codebase. It also allows us to see this clone in CI, before the PR is merged, giving the developer a chance to remove it.
As an example, see commit (a8e4860) where a copy-pasted function is added, and notice that CI fails and displays only the section of the report relevant to this clone. Then, once we remove this work in the following commit (53d3973), the check passes.
Included in this PR, is that it runs only on
pull_request
and no longer onpush
.Notes
jscpd
is not perfect and was not able to detect the clone added in (e7357c0). Will need to dig deeper into their algorithm (based on https://en.wikipedia.org/wiki/Rabin%E2%80%93Karp_algorithm) and implementation (https://github.com/kucherenko/jscpdto) to understand why this is missed, and if it presents a larger problem.Future Work
minLines
argument that provides the desired sensitivity. This argument allows us to ignore clones underminLines
in length. Right now it is 3, which is likely too granular, but better to start there and loosen as needed.License: I confirm that my contribution is made under the terms of the Apache 2.0 license.