Sonarlint not scanning Kotlin files

Problem description: Sonarlint will scan Java but not Kotlin source classes.

We have a local installation of SonarQube version 8.9.1.44547 and are using IntelliJ with SonarLint (I have 5.2.0.35150 but version doesn’t seem to matter).

SonarLint is connected via token to the SonarQube server and is bound to the project. There are no Analysis Properties configured (and I don’t know where these are documented, so maybe that’s my problem).

When I run a report across all project files, the only problems found are in MavenWrapperDownloader.java (which of course isn’t even in src/). The Kotlin code doesn’t show any problems. According to the logs, SonarLint is happily talking with SonarQube.

I expect there’s some simple bit of misconfiguration here, but my search-fu isn’t finding anything that helps. What am I missing?

Hello @twheeler,

Welcome to the community!

There are a couple of things we need to check to identify where the problem is. First of all, do you see the same situation in SonarQube? (No issues on Kotlin files) Are you using maven or gradle scanner or just sonarscanner?

Could you also provide the logs of the sonarqube analysis?

Thanks,
Margarita

Hi @Margarita_Nedzelska, thanks for the welcome and reply,

Yes, SonarQube does show violations, and in the logs (attached, somewhat condensed for brevity) I can see the scan running using the detekt profile.

sonar_log.txt (4.7 KB)

I’ve got the feeling that all the Kotlin issues you see on SonarQube side are provided by the external linter “detekt” and that there is no issue raised on Kotlin files by the internal Kotlin analyzer provided by SonarQube.
If this is confirmed, this would explain why you see no Kotlin issues on SonarLint side. SonarLint runs only the SonarSource analyzers and don’t run “detekt”.

We experience similar problems. Just sent in this ticket to sonatype:

A couple of teams of [4000+ developers company] use SonarLint in their IntelliJ IDE programming in Kotlin.
Now, for Java code all issues appear on the fly in the SonarLint plugin, also PMD en Checkstyle rules. Also using the ‘Sonar Way’ build in evaluation for Kotlin all issues arise as expected.

But the situation is our quality gate contains Detekt rules, provided by the Detekt plugin. https://github.com/detekt/sonar-kotlin
We would love to have these issues visible in IntelliJ, just like PMD, Checkstyle and others.

Is there a possibility you can provide this functionality?
Or is there anything we can do to provide this functionality to our SonarQube users?

Hi,

I guess that for PMD and Checkstyle, you are using a dedicated plugin, because SonarLint is not supposed to run third party analyzers.
Why not also using the Detekt plugin for IntelliJ?

Correct, we’re using detekt in our scan, so if SL only runs the internal linters that explains why.

We can use the detekt plugin though as @Maarten_Klok notes above, it would be great to see everything in one place.

Is there a recommended way to configure so that both detekt and SQ use the same rules/configuration?

Well, let’s see things a little bit differently. The only way to get a good user experience between IDE and SQ is finally to no longer need to rely on Detekt at all. In order to achieve this, we need to re-implement some of the useful Detekt rules into SonarQube and SonarLint so that they come out of the box.

It would be great if you Kotlin experts, could create a list of “must-have”, “nice-to-have”, “not needed” rules from Detekt so we can better prioritize our work.