Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does code duplicate detection work for TypeScript language in SonarQube?

I am using SonarQube version 5.6. Using TypeScript plugin from https://github.com/Pablissimo/SonarTsPlugin. Code coverage and Code Smells are working but not duplicates though. Based on the following log, it seems like it is not supported. Does anyone know of a way to check for duplicates in TypeScript code?

Here's the relevant section from the batch job:

10:52:15 INFO: Sensor CPD Block Indexer (wrapped)
10:52:15 INFO: DefaultCpdBlockIndexer is used for ts
10:52:15 DEBUG: No CpdMapping for language ts
10:52:15 INFO: Sensor CPD Block Indexer (wrapped) (done) | time=0ms
10:52:15 INFO: Calculating CPD for 0 files
10:52:15 INFO: CPD calculation finished

like image 934
Ganesan Avatar asked Apr 09 '26 08:04

Ganesan


2 Answers

Try to use SonarTS, official plugin developed by SonarSource https://github.com/SonarSource/sonarts

like image 195
Elena Vilchik Avatar answered Apr 10 '26 23:04

Elena Vilchik


If you're open to a non-Sonar solution, I found https://github.com/kucherenko/jscpd to work well. Here is an example output:

jscpd --pattern=**/*.ts src/

Produced:

Clone found (typescript):
 - src/file1.ts [146:12 - 153:6] (7 lines, 93 tokens)
   src/file2.ts [122:2 - 130:6]

...lots of lines like that...

┌────────────┬────────────────┬─────────────┬──────────────┬──────────────┬──────────────────┬───────────────────┐
│ Format     │ Files analyzed │ Total lines │ Total tokens │ Clones found │ Duplicated lines │ Duplicated tokens │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ typescript │ 299            │ 12781       │ 95718        │ 40           │ 685 (5.36%)      │ 5318 (5.56%)      │
├────────────┼────────────────┼─────────────┼──────────────┼──────────────┼──────────────────┼───────────────────┤
│ Total:     │ 299            │ 12781       │ 95718        │ 40           │ 685 (5.36%)      │ 5318 (5.56%)      │
└────────────┴────────────────┴─────────────┴──────────────┴──────────────┴──────────────────┴───────────────────┘
Found 40 clones.
Detection time:: 1.286s
like image 33
josephdpurcell Avatar answered Apr 11 '26 00:04

josephdpurcell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!