-
Notifications
You must be signed in to change notification settings - Fork 36
Add copy/pasting detection #3149
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
base: main
Are you sure you want to change the base?
Conversation
How do I test this? |
This is likely not ready for testing yet because the front-end tests are failing - but that's the intention of the change The change will make front-end tests fail if code duplication is detected. As soon as code duplication issues are fixed, the tests will be pass, and thus this will be ready for merging |
I could see one issue with this though, not sure it's important enough to fix, but something to consider: I made a change where back-end test are only run on back-end changes, and front-end tests are run on front-end changes. However, the code duplication check is checking both front-end and back-end - yet is only run if the front-end changes. The worst case is that a pull request that added code duplication on the back-end gets merged, and then front-end test will start failing for people. The fix for this would be to modify |
a nice side-effect of adding this library: (and it ignores the test files and third-party libraries, so the numbers are not inflated like in sp6) Shows that front-end is |
specifyweb/frontend/js_src/lib/components/DataModel/legacyTypes.ts
Outdated
Show resolved
Hide resolved
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.
All good (besides the failing tests)
@melton-jason can you please take a look into the following code duplication occurrences:
see how easy it is to fix them (if deduplicating them is adding a lot of complexity, then we can silence the duplication check for those two occurrences) |
@realVinayak can you also look into resolving the following. should be relatively simple
|
These duplicates are related to the fact that subclasses of Named Tuples are not meant to be subclassed themselves. In short, the backend is extensively using Named Tuples to store information about the status of an upload. specify7/specifyweb/workbench/upload/upload_plan_schema.py Lines 228 to 245 in 393538b
and NamedTuples are immutable once created. Through the process of uploading or validating a workbench upload plan, the backend 'converts' NamedTuple classes into ones that have more information or are more 'specialized', up until the actual upload/validation. (A typical example of the conversion process is UploadTable -> ScopedUploadTable -> BoundUploadTable) Because we can not subclass a generic UploadTable in ScopedUploadTable, BoundUploadTable, etc., we have to reuse a lot of the 'generic' functionality common to all of them. |
@melton-jason not a problem we can leave it as is given that it is presenting issues. We have the capability to silence those errors by adding comments like this - 9c52034#diff-c8cfcd0e13a828573c0d195ee26ce1cbb513e3554e37dcb0860e9053ffa16568R73-R121 Though, the issues in #3149 (comment) would be easy to fix so should be fixed |
@melton-jason do we want to merge this at some point? |
Yes, we can look into merging this. |
Is this a feature that requires any UX Testing? @CarolineDenis |
@carlosmbe , no it does not |
@specify/dev-testing |
Would love to see this merged. |
# OS | ||
.DS_Store | ||
|
||
# Editors | ||
/.vscode/ | ||
/.idea/ |
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 used to be against OS or editor specific gitignore patterns, and was recommending using global gitignore for that but I changed my mind.
Reasons:
- Setting up global gitignore is added friction, especially for new team members or external contributors.
- Automated tools (like jscpd, eslint, prettier) and some IDEs do not look into global gitignore file
I just realized that jscpd will also help us detect incorrect merge resolutions (i.e cases when a deleted file got incorrectly "resurected" during merging). Pretty nice |
Testing instructions:
|
SCHEMA['toManyIndependent'] & | ||
SCHEMA['toOneDependent'] & | ||
SCHEMA['toOneIndependent'])[FIELD_NAME] | ||
FIELD_NAME extends SchemaFields<SCHEMA>, |
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.
Re-run npx tsc --extendedDiagnostics
several times with and without this change
seems like this change makes typescript type-checking of entire project faster between 0s and 1s (possibly because TypeScript can cache the resolved type?)
@@ -37,6 +37,7 @@ def get_cols(self) -> Set[str]: | |||
| set(col for u in self.toOne.values() for col in u.get_cols()) \ | |||
| set(col for rs in self.toMany.values() for r in rs for col in r.get_cols()) | |||
|
|||
# jscpd:ignore-start |
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.
regarding backend workbench, is there a way to silence the workbench ones for now? They should be fixed in this #4929 - I reworked the matching, and deleted everything from the tomany.py file 😄 (made the logic completely generic, no need for that file anymore, see diff).
Sounds good. Leaving these to you
9c442ee
to
64b09fa
Compare
@maxpatiiuk, |
You can run the check locally at any point by calling this command from the npx tsx lib/tests/jscpd.ts We could have it run automatically in a pre-commit hook, however the command takes 11s to check entire specify7 repository, so this would slow down commits considerably. I know that IntelliJ IDEs had this built-in live in the editor. Maybe there is a VS Code plugin for that too - but I imagine it would slow down the IDE a bit. |
4196b97
to
a4dd9d3
Compare
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.
- Verify that the Tabs buttons in app resources still look good after the change
- Verify that the "Table Format"/"Table Aggregation" tabs in the
- Go to User Tools -> Operations API -> Verify that the documentation for the
/context/user_resource/*
and/context/collection_resource/*
endpoints looks good (or better) than production
Looks good so far! For the "Table Format"/"Table Aggregation" tabs, what exactly should we be focusing on testing here?
ups! looks like I lost my train of thought when I was typing that 😆 |
Triggered by 64b09fa on branch refs/heads/issue-2996
e00d6a9
to
61bc8d7
Compare
Triggered by 61bc8d7 on branch refs/heads/issue-2996
Fixed #2996
edit: testing instructions