- Operating system: Windows 10 Enterprise, 10.0.19042
- SonarLint plugin version: 126.96.36.199872
- Programming language: C/C++
- Is connected mode used: Yes
- Connected to: SonarQube Developer Edition 188.8.131.52466
I have a problem that SonarLint will use the C quality profile instead of the C++ quality profile for some header files. The verbose log shows this (sensitive information redacted):
[ThreadId 17] [DEBUG] [CompilationConfigProvider] Reading compilation database from '***\compile_commands.json' [ThreadId 17] [DEBUG] [CompilationConfigProvider] Header file detected, searching for matching code file. File: ***\ABC.h [ThreadId 17] [DEBUG] [CompilationConfigProvider] Header file: using first entry: ***\EFG.c [ThreadId 17] Loaded settings from "***\AppData\Roaming\SonarLint for Visual Studio\Bindings\***\c_settings.json".
As far as I understand SonarLint will look for a .c or .cpp file with the same name as the .h file. If none is found it will take the first entry from the compile_commands.json file and whatever language the first file has, this language will be used for the analysis of this .h file.
The first entry in my compile_commands.json file is unfortunately a .c file. The header file has C++ code in it and is then checked against the C quality profile which is wrong. No findings are found with SonarLint but in SonarQube the right quality profile is applied and the C++ issues are found.
What is the exact algorithm if no .c/.cpp file with the same name is found and how can I fix this?
I am very grateful for any help!