danielstjules / jsinspect

Detect copy-pasted and structurally similar code
MIT License
3.57k stars 128 forks source link

Allow programmatical use of jsinspect #1

Closed leny closed 10 years ago

leny commented 10 years ago

Hi,

You've done a very great work on jsinspect, it's a great, great tool.

If I may suggest a little modification : the possibility to use jsinspect programmatically, without the CLI-interface, by exposing the lib/inspector.js file to the main property of the package.json file, and maybe integrate a callback support for the results, allowing (and facilitate) the use and integration of jsinspect in other tools, and tasks runners like grunt or gulp, by example, and with the promise mecanisms like async.

Regards,

danielstjules commented 10 years ago

Thanks for the issue! I could def expose lib/inspector.js, though it's probably not as helpful without a reporter. In the meantime, it could be accessed with require('jsinspect/lib/inspector') The same goes with the reporters themselves. Someone made a grunt plugin for a similar project, buddy.js, which follows that rough idea https://github.com/eugene-bulkin/grunt-buddyjs/blob/master/tasks/buddyjs.js

As for making it async, it's a CLI tool, and one with the equivalent of tight loops. Introducing async iteration would have a huge impact on performance. And it couldn't really be made async, since there's critical operations that are fully blocking, such as acorn's AST parsing, and the diff generation. I used promises a bit with buddy.js too, and I'll likely switch away from it, as it offers no benefit. Since it's a command line task, and not a server, I don't need to yield execution to any other resources running in that instance of node.

In regards to the results, they can be collected pretty easily by registering a listener to the "match" event. By rendering them progressively, a task would look far more responsive for a large project, rather than batching them all at the end.

I realize this is all just one point of view, but hopefully my reasoning isn't too poor!

danielstjules commented 10 years ago

Hope you don't mind if I close this, and let me know if you have any other comments or suggestions! :)

leny commented 10 years ago

Thanks for your clarifying answer, I don't have anything to ask about this with these explications. :+1:

++