Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

code duplication in javascript

Is there any tool to detect code duplication in JavaScript? I tried "PMD Duplicate code detector" but it is not supporting .js extension.

like image 929
chandra Avatar asked Oct 19 '10 08:10

chandra


2 Answers

I would recommend JSCPD

Installation

npm install -g jscpd

Run

jscpd ./path/to/code

(you have several type of reporters, default is console, but you can use html like this: jscpd -r html ./path/to/code)

Other solutions:

  • JSinspect wasn't good for me because didn't support .ts and .tsx (jscpd supports 150+ formats
  • InteliJ IDEs (I'm a big fan of them) don't seem to work since WebStorm found no duplicated code.
like image 107
Cramer Gabriel Avatar answered Oct 12 '22 00:10

Cramer Gabriel


You can use JS Inspect it detects copy-pasted and structurally similar code, also supports *.js

Installation

npm install -g jsinspect

Run

jsinspect -t 50 ./path/to/src
like image 28
Shashank K Avatar answered Oct 12 '22 00:10

Shashank K