AndroidDev
AndroidDev

Reputation: 5575

Finding duplicated code (Kotlin) in Android Studio

Is there a way to find duplicated (Copy/pasted code, repeated code) Kotlin code in Android Studio? I have Android Studio 4.0 but can't find this "Duplicated code fragment" option.

Are there any Android Studio plugins that do this job for Kotlin?

Upvotes: 4

Views: 1934

Answers (1)

jeprubio
jeprubio

Reputation: 18022

You can install the sonarLint plugin.

It has many rules which are executed on source code to find possible issues like bugs or code smells.

example 1

This is done with the rules provided by default.

Other example of repetition:

example 2

Just need to install the sonarLint plugin in Preferences/Plugins:

sonarLint

A more advanced tool you could check is Gradle CPD plugin. This is a Gradle plugin to find duplicate code using PMDs copy/paste detection (= CPD). You can find information about how to install it and how to use it in the same readme of the repository. CPD supports Kotlin since v6.10.0.

Upvotes: 5

Related Questions