Skip to content
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

How do I find locations and snippets in a folder that are similar to the specified code snippet? #727

Open
Flcwl opened this issue Dec 13, 2024 · 2 comments

Comments

@Flcwl
Copy link

Flcwl commented Dec 13, 2024

Now I have a code snippet. like it:

const targetFunc = (a, b, c) => {
  return a + b  + c
}

I need find the code locations similar to function targetFunc in src. how I can do it ?

  • src/a.js
const sum3 = (a, b, c) => {
  return a + b  + c
}

sum3(1, 2, 3)
  • src/b.js
const sum = (a, b) => {
  return a + b
}

sum(2, 3)
@mark-hahn
Copy link

I want this also.

@mark-hahn
Copy link

mark-hahn commented Feb 24, 2025

I asked github copilot: can JSCPD compare one small section of code to many large files?

It answered ...

Yes, JSCPD can compare a small section of code against many large files. You can specify the path to the directory containing your large files, and JSCPD will scan all the files within that directory for duplicate code, including the small section you are interested in.

Here is how you can do it:

Create a file with the small section of code: Save the small section of code you want to compare in a separate file, for example, small-section.js.

Run JSCPD: Use JSCPD to compare the small section against the large files. You can specify multiple paths if needed.

This command will compare the code in small-section.js against all the files in the src directory.

JSCPD will then generate a report showing any duplicate code it finds between the small section and the larger files. This allows you to effectively compare a small piece of code against a larger codebase.

EDIT: I just realized that this is not really what we want. We want only matches to the small section. The solution offered would also find matches between sections in the large files unrelated to the small selection. This also means it would be spending a large amount of unneeded resources.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants