• Welcome to Dark Bit Factory & Gravity.
 

Javascript Copy&Paste Detection

Started by benny!, January 03, 2012

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

benny!

Hi,

does anyone of you know a Copy&Paste detection tool (preferably free) that works for JavaScript. What I am looking for is something like PMD for Javascript.

Any help is appreciated.

Best,
benny!
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

combatking0

Do you mean copied & pasted code or the use of the paste feature at runtime?
You are our 9001st visitor.
Challenge Trophies Won:

benny!

I mean Copy&Pasted code - basically a programm which parses the complete javascript sourcecodes and checks for redundant code bits.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Raizor

I've got some code that reads the contents of the clipboard that I use at work for pasting a license key using javascript:

var PastedText = document.getElementById("textfield").createTextRange();
PastedText.execCommand("Paste");

I've only tested that in IE, so not sure if it works in other browsers. It's attached to a button click event, you might need to do the same as I doubt arbitrary clipboard access is allowed.
raizor

Challenge Trophies Won:

benny!

Thanks Raizor.

But what I am looking for is a programm that scans the files/sources on the harddisk and parses the javascript and compares across all files if there are redundant code bits. I want to add this into our build process, so all programmers get notified when checking in redundant code into our SVN.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Raizor

Hmm, so a file compare that compares functions within different js files to determine if they are the same?
raizor

Challenge Trophies Won:

benny!

Quote from: Raizor on January 04, 2012
Hmm, so a file compare that compares functions within different js files to determine if they are the same?

Kind of. Those programms do not simply compare files line by line. They really parses the code and see if they are redundant parts of a certain size (on a compiler-like basis). In addition those programms checks for unreachable code, unused variables and stuff like that. There are some cool tools available for PHP, Java and I guess C++, too - but I cannot find a working solution for javascript code.
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

benny!

To find duplicate code those programms use the so called Rabin Karp Algorithm and basically I have such kind of programs in mind:

PMD Software
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

Raizor

Ah, I see. That could be very useful, yeah :)

Apparently this handles javascript:

http://www.semdesigns.com/Products/Clone/ECMAScriptCloneDR.html

Not sure how much it costs, but there's an eval version available.

raizor

Challenge Trophies Won:

hellfire

Quote from: benny! on January 04, 2012
To find duplicate code those programms use the so called Rabin Karp Algorithm
Quote from: wikipediaA practical application of Rabin–Karp is detecting plagiarism.

Do you really want to find redundancy or do you just want to know where your colleagues ripped their code? ;)

In my opinion it's the wrong approach:
This way some automatism will tell me that the code I've just written already exists, so my work was useless.
Instead just do a good documentation of existing modules and the redundant code won't be written in the first place.
Challenge Trophies Won:

benny!

@HellFire:

No, I really just need to find redundant code this time. Totally, agree with you in general, with clean software design and good documentation you can avoid most of the redundancy beforehand. However, current project is a bit different. Projectmangement is not in our hands and it is extremely agile - that's why we agreed of having a certain level of redundancy. Of course having in mind that each sprint we have a look at what certain mess detection software says and then discuss it together.

Well downloading evaluation suite of the software raizor mentioned to see how it works ...

[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won:

benny!

Just want to provide a small update - I downloaded the ECMAScriptCloneDR tool (evaluation copy) - and did a test run with the IDE on my project. It crashes with unhandled java exceptions. Really frustrating ...
[ mycroBLOG - POUET :: whatever keeps us longing - for another breath of air - is getting rare ]

Challenge Trophies Won: