how to configure sonarlint in VScode for C language?

4.1k views Asked by At

I'm practising clean code and I installed sonarlint as a static testing tool to help me write clean code. after installing the editor rises this notification

SonarLint is unable to analyze C and C++ file(s) because there is no configured compilation database.

after some searching, I found that I should add a file with a name

compile_commands.json.

this file should be exported automatically by cmake after adding this option

CMAKE_EXPORT_COMPILE_COMMANDS

where can I add this option in VScode.

this link is where the vscode redirected me to creat the required .json file

1

There are 1 answers

0
The Broken Engineer On

I am assuming that you are using CMake for your build. If that is the case then add the following line to the CMakeLists.txt

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Then build the project and the database will be created for you.