Author Topic: Javascript Copy&Paste Detection  (Read 6333 times)

0 Members and 1 Guest are viewing this topic.

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Javascript Copy&Paste Detection
« on: January 03, 2012 »
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:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: Javascript Copy&Paste Detection
« Reply #1 on: January 03, 2012 »
Do you mean copied & pasted code or the use of the paste feature at runtime?
You are our 9001st visitor.
Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #2 on: January 04, 2012 »
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:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: Javascript Copy&Paste Detection
« Reply #3 on: January 04, 2012 »
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:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #4 on: January 04, 2012 »
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:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: Javascript Copy&Paste Detection
« Reply #5 on: January 04, 2012 »
Hmm, so a file compare that compares functions within different js files to determine if they are the same?
raizor

Challenge Trophies Won:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #6 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:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #7 on: January 04, 2012 »
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:

Offline Raizor

  • Founder Member
  • Pentium
  • ********
  • Posts: 1154
  • Karma: 175
    • View Profile
Re: Javascript Copy&Paste Detection
« Reply #8 on: January 04, 2012 »
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:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Javascript Copy&Paste Detection
« Reply #9 on: January 04, 2012 »
To find duplicate code those programms use the so called Rabin Karp Algorithm
Quote from: wikipedia
A practical application of 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:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #10 on: January 04, 2012 »
@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:

Offline benny!

  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4384
  • Karma: 228
  • in this place forever!
    • View Profile
    • bennyschuetz.com - mycroBlog
Re: Javascript Copy&Paste Detection
« Reply #11 on: January 05, 2012 »
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: