13

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

1

4 Answers 4

11

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.
Sign up to request clarification or add additional context in comments.

Comments

2

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

1 Comment

Caveat from jsinspect's README: Note: the project has been mostly rewritten for the 0.10 release.
0

I would recommend looking at this thread (also on stackoverflow): Javascript source code analysis ( specifically duplication checking )

Comments

0

IDE can have this functionality. I use IntelliJ, this IDE has a built-in duplicate code checking mechanism at 2 scopes:

  • Inline: Duplicate codes are underlined when opened in editor so that developer can easily catch and do refactoring.
  • Analysis: Go to menu Analyze->Locate Duplicates.., specify scope to run through and list all duplications.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.