SonarLint do not find issues (0 issues found)

Dear all,

Thank you for providing a C family plugin in vscode with Sonarlint.

  • Operating system: Windows
  • IDE name : VSCode 1.66
  • SonarLint plugin version: V3.4.1
  • Is connected mode used: No only on the flow

I am trying to use SonarLint in VSCode or a project that use MSVC and CMake. To have a compile_commands.json, I create a “false” file by only setting the parameters file, directory and command (with the value whatever for the latter).

SonarLint verbose log and Analyzer show that file is parsed but it always finds 0 issues.

Is it mandatory to have a compiler set-up in compile_commands.json ?
I was thinking that only file and directory are used to compare file.

Thank you.

[Info  - 03:25:40.288] Index files
[Debug - 03:25:40.290] Language of file 'file:' is set to 'C++'
[Info  - 03:25:40.299] 1 file indexed
[Debug - 03:25:40.308] 'JavaSensor' skipped because there is no related files in the current project
[Debug - 03:25:40.309] 'Python Sensor' skipped because there is no related files in the current project
[Debug - 03:25:40.309] Execute Sensor: CFamily
[Info  - 03:25:40.315] Parsing compilation database 
[Debug - 03:25:40.317] Time to parse Compilation Database: 2ms
[Info  - 03:25:40.318] main.cpp using compilation database entry with same name and different directory: test_lint/main.cpp
[Info  - 03:25:40.319] Subprocess(es) done in 9ms
[Info  - 03:25:40.319] 0 compilation units analyzed
[Debug - 03:25:40.320] Execute Sensor: Sonar Secrets Detection Sensor
[Debug - 03:25:40.321] 'PHP sensor' skipped because there is no related files in the current project
[Debug - 03:25:40.321] 'Analyzer for "php.ini" files' skipped because there is no related files in the current project
[Debug - 03:25:40.322] 'XML Sensor' skipped because there is no related files in the current project
[Debug - 03:25:40.322] Execute Sensor: HTML
[Info  - 03:25:40.342] Found 0 issues

Welcome to the community, @Joh!

For the plugin to work correctly, it needs to be able to find the command that corresponds to the compilation of a given file in the compile_commands.json. In other words, it is mandatory that compile_commands.json represents the compilation of the project and contains entries for all analyzed files.

There are several methods to generate a Compilation Database. The appropriate one will depend on your toolchain. For example:

  • if you are using CMake, set the “CMAKE_EXPORT_COMPILE_COMMANDS” option
  • if you are using Xcode, use xcpretty

Thank you for your reply @Tomasz_Kaminski .

Unfortunately CMake export do not work with MSVC build.
My compile_commands.json already represents the project entries for file and directory but only command is set to a wrong data.
If I understand well, you mean that command value should also be filled with a good value adapted to the current project ?

Yes, all fields in the compilation database need to be filled with correct data, including the command field. This is important, as this field contains compiler flags that affect the analysis (like the standard version).

You may also check the following page for more options on generation for compilation database.

Really appreciate your help.
Thank you.

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