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
Cannot run detectInFiles()
several times in a row
#207
Comments
I just tried with
It's better but I think |
Another way to reproduce the issue with 'use strict'
const { JSCPD } = require('jscpd')
const instance = new JSCPD({ minTokens: 35 })
const jscpd = () => instance.detectInFiles(['bug.js'])
jscpd().then(jscpd) Output:
|
To put some context into this: the reason this is a problem is when |
Temporary Solution 'use strict'
const { getStoreManager, JSCPD } = require('jscpd')
const instance = new JSCPD({ minTokens: 1, minLines: 1 })
const detect = async function() {
const clones = await instance.detectInFiles(['example.js'])
console.log(clones)
await getStoreManager().close(); // Temporary Solution
}
detect().then(detect) |
Hi, I'm back. Currently I'm going to release new version of jscpd@3.3.0 and test functionality with jscpd@3.3.0-rc.3. So, jscpd moved to monorepo and API changed. For run cli version use following code: import {IClone} from '@jscpd/core';
import {jscpd} from 'jscpd';
const clones: Promise<IClone[]> = jscpd(process.argv);
(async () => {
const clones: IClone[] = await jscpd(['', '', '/path/to/file/or/folder', '-m', 'weak', '--silent']);
})(); If you are going to detect clones in file system you can use @jscpd/finder for make a powerful detector. In case of detect clones in browser or not node.js environment you can build you own solution base on @jscpd/core. the functionality still in RC, it would be great if you can provide any feedback regarding the functionality and new API. I will release soon to main branch and close the issue. More info located here - jscpd monorepo |
fixed in jscpd@3.3.0-rc.9 |
Describe the bug
When running
detectInFiles()
several times in a row, the second run re-uses state from the previous run. This leads to files reporting duplication "on themselves" (i.e.duplicationA
andduplicationB
are the same line in the same file, for all lines in all files).To Reproduce
example.js
:bug.js
:Output:
Expected behavior
No clones should be returned.
Possible cause
It seems like the store state is not cleaned between run. I'm not sure if this is intentional.
In
jscpd.js
line 244 there are two possible problems:EventEmitter.emit()
is synchronous with both core Node.js andeventemitter3
. So it should be afterEventEmitter.on()
. This causesStoresManager.close()
to never be closed.EventEmitter.once()
should probably be used instead. Otherwise re-running the main path will setup an additional end listener.Desktop (please complete the following information):
18.10
11.10.0
2.0.9
Additional context
Note the
(node:30646) Warning: No such label 'Execution Time' for console.timeEnd()
at the end, which is probably a separate bug.The text was updated successfully, but these errors were encountered: