SonarLint IntelliJ plugin for Kotlin doesn't detect an unused variable

kotlin

(Dimitar Mahmudiev) #1

SonarLint plugin for IntelliJ detects errors as expected for the following code in Java:

public class Test {
private String CONST = “Constant”;
}
The same code in Kotlin generates no errors:

class TestKotlinn {
private val CONST = “Constant”;
}
[Note] This is not a test class, it’s just a standard class containing no other code.
Expected: SonarLint for Kotlin should say “Remove the unused CONST private field” the same way it does for Java, and also the same way IntelliJ shows a warning.

IntelliJ version: IntelliJ IDEA 2018.2.6 (Ultimate Edition), Build #IU-182.5107.16, built on November 6, 2018
JRE: 1.8.0_152-release-1248-b22 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
OS: macOS 10.13.6

SonarLint IntelliJ plugin: Version: 4.0.0.2916

Screenshots (link to a Tweet): https://twitter.com/dmahmudiev/status/1064927781342064640


(Alban Auzeill) #2

Hi Dimitar,

It’s not a false negative, it’s because SonarKotlin supports the rule S1481 about unused local variable, but not yet the rule S1068 about unused private field.
Please note that SonarJava has 529 rules and SonarKotlin 43. Furthermore SonarKotlin does not yet have the same level of accuracy as SonarJava, so do not except the same result for now.

But the competition just start, let’s beat SonarJava \o/ !

Alban


(Dimitar Mahmudiev) #3

Hi Alban,

Thanks for clarifying. This makes sense now.
Looking forward to the more rules on SonarKotlin. I quite like SonarJava so if SonarKoltin beats it I’ll be very happy!

Thanks,
Dimitar