Code Smells detected by Sonarqube server but not VSCode'sonarlint addon

  • Operating system: Virtual machine (VirtualBox) with Rocky8.7
  • SonarLint plugin version: v3.15.1
  • Programming language : Javascript
  • Connected to SonarQube (v8.9.2)

We are using Sonarlint connected to our Sonarqube server but when operating the code analysis the “Code Smells” is not detected by Sonarlint (even if it is detected by Sonarqube server).

The Code Smells is the following : “Refactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed.” on a file called “OverlayMetar.js”.

Sonarlint logs in VSCode :

[Info  - 12:27:31.034] Started request handler on port 6000
Initializing file:///home/serv/serv_Project_react on branch develop
[Info  - 12:27:46.783] Downloaded plugin list in 95ms
[Info  - 12:27:46.787] [SYNC] Synchronizing analyzer configuration for project 'Project:serv:react'
[Info  - 12:27:46.952] Downloaded settings in 154ms
[Info  - 12:27:47.146] [SYNC] Fetching rule set for language 'css' from profile 'AWxv9Mpd_NlBnXHk95Se'
[Info  - 12:27:47.349] [SYNC] Fetching rule set for language 'java' from profile 'AWxv9NHD_NlBnXHk95_6'
[Info  - 12:27:47.813] [SYNC] Fetching rule set for language 'js' from profile 'AWxv9M88_NlBnXHk95wR'
[Info  - 12:27:47.965] [SYNC] Fetching rule set for language 'php' from profile 'AWxv9NRR_NlBnXHk96KU'
[Info  - 12:27:48.093] [SYNC] Fetching rule set for language 'py' from profile 'AYMcL0Q9uF11nAESp7dp'
[Info  - 12:27:48.228] [SYNC] Fetching rule set for language 'ts' from profile 'AWxv9NZN_NlBnXHk96X3'
[Info  - 12:27:48.415] [SYNC] Fetching rule set for language 'web' from profile 'AWxv9NK4_NlBnXHk96Fr'
[Info  - 12:27:48.539] [SYNC] Fetching rule set for language 'xml' from profile 'AV15vGmplOxF8Oq-U3yl'
[Info  - 12:27:48.693] [SYNC] Synchronizing project branches for project 'Project:serv:react'
[Info  - 12:27:54.338] Analyzing file 'file:///home/serv/serv_project_react/sources/src/mapManager/Controls/OverlayMetar.js'...
[Info  - 12:27:56.649] Skip downloading hotspots from server, not supported
[Info  - 12:28:12.862] Found 0 issues

The Code Smells rule is correctly downloaded from Sonarqube server to VSCode :
image

Is it a known Sonarlint bug ? What can we do ?

NB : This Code Smells isn’t indicated anymore in the new Sonarqube version.

1 Like

Hello @NicolasRMOD and welcome to Sonar Community! :wave: :sonar:

I’d like to clarify what do you mean when you say

This Code Smells isn’t indicated anymore in the new Sonarqube version.

If the code smell has been marked as Won't Fix or False Positive on the SonarQube side, the issue will also be hidden in SonarLint when in Connected Mode.

I hope it helps,
Sophio from SonarLint :sonarlint: :slight_smile:

Hi Sophio,
Their was a mistake in our analysis, the code smells is still detected in Sonarqube 9.9 LTS, but it doesn’t really matter because the current version our company is using is the one indicated (8.9.2).
Moreover the code smells is not tagged as Won't Fix or False Positive like you are suggesting.

Got it, thank you for the clarification.

In SonarLint for VSCode, we always embed the JavaScript analyzer, even in Connected Mode. This means that, since your SonarLint is the latest version, it uses the latest version of the JS analyzer. On the other hand, your SonarQube is relatively old and uses an older version of the analyzer. I think this should be the cause for the mismatch between the issues remotely and locally.

The easiest path would be to update to the latest SonarQube :sonarqube:

Best,
Sophio

This issue seems related to Add exception to Cognitive Complexity for React functional components · Issue #2238 · SonarSource/SonarJS · GitHub

It seems SonarQube counts complexity of the function with nested functions whereas Sonarlint counts the complexity per function, without nested.

We tried the same analysis by connecting VSCode’sonarlint to a sonarqube 9.9 server and the code smells is still not detected by sonarlint. However we tried to add 3 imbricated “if” in the OverlayMetar.js file and now sonarlint detects a comlexity highter than 15. (See Matthieu’s post related to this issue).

Are you still having the issue? Are you using the latest SonarLint version?

With SonarQube v9.9.1.69595, the error does not occur anymore.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.