# Setting up SonarLint to analyse C/C++ in VS Code ### About Sonarlint [Sonarlint](https://community.sonarsource.com/t/c-c-support-in-vscode/4732/26) is a FOSS static analysis tool that can do lint and [much more](https://www.sonarlint.org/features/). I started using cppcheck and uncrustify when I was developing code for RIOT-OS. Recently I came across SonarLint, which offers far more features. Initially, support for C was only available in Clion; later after repeated requests from the community, Sonarlint [finally supports ](https://community.sonarsource.com/t/sonarlint-for-visual-studio-code-3-4-released-support-for-c-and-c/61110)C/C++ in VS Code. ### Requirements This document is for developers coding in C using VS Code in a Linux environment. I use a Linux machine ([Manjaro](https://www.sonarlint.org/features/)); the approach should be similar if you use WSL. ### Setup 1. Install [SonarLint Plugin](https://www.sonarlint.org/vscode) 2. Sonar Lint needs a [compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) for lint operations. This can be generated in several ways, which is documented [here](https://github.com/SonarSource/sonarlint-vscode/wiki/C-and-CPP-Analysis). I used [makefile tools extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode.makefile-tools) and followed this [guide](https://devblogs.microsoft.com/cppblog/makefile-tools-december-2021-update-problem-matchers-and-compilation-database-generation/) 3. Restart VS Code IDE and then the makefile tools extension will start generating the compile commands and store them in `compile_commands.json` file in your local `.vscode` folder. 4. Sonarlint should now scan open files in you workspace for errors / deviations from the [rules](https://rules.sonarsource.com/c) 5. If you have a Sonar cloud account, you can connect to the same and sync rules. ### Conclusion I use Sonar Lint extensively in my workflow, but I still use uncrustify to ensure indents /spaces/ brackets are well aligned. I will continue using cppcheck for its support for [custom rules](https://github.com/embeddedartistry/cppcheck-rules). As far as I know, Sonarlist supports custom rules only if connected to Sonar Cloud !! Importing cppchecks rules are not supported, so even with a Sonar cloud account, it would be a painstaking process to have custom rules!