-
Notifications
You must be signed in to change notification settings - Fork 77
Overview of C and Cpp analysis
The content on this page has moved: https://docs.sonarsource.com/sonarlint/visual-studio/using-sonarlint/scan-my-project/#supported-project-types
The SonarLint documentation has moved! Please visit https://docs.sonarsource.com/sonarlint/visual-studio/ to have a look at the new documentation website. We’ve improved the documentation as a whole, integrated the four SonarLint IDE extension docs together, and moved everything under the sonarsource.com domain to share a home with the SonarQube docs (SonarCloud to come in Q3 of 2023).
These GitHub wikis will no longer be updated after October 1st, 2023 but no worries, we’ll keep them around a while for those running previous versions of SonarLint for Visual Studio.
SonarLint can analyse .vcxproj projects that use the standard Visual Studio compilation tools. Projects that use third-party tools (such as Unity projects) are not supported.
Visual Studio 2017 and later support opening CMake projects in the IDE (see the Microsoft documents for more information).
Starting with v4.38, SonarLint can analyse a subset of CMake project types that meet the following requirements:
- Visual Studio 2017 Update 3 or later is used
- Visual Studio is configured to use the Ninja generator (the default), and
- the CMakeLists.txt file contains the following command:
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
.
See the Getting Started with analyzing CMake projects in Visual Studio for more information.
C/C++ analysis is triggered when a file is opened or saved. Any existing issues for the document will immediately be removed from the Error List. New issues will be added to the Error List incrementally as they are detected.
The status bar will be updated to show the file is being analysed...
... and again when analysis has finished:
Additional detailed information will be shown in the SonarLint pane of the Output Window.
Note: SonarLint only displays status information in the status bar, as shown in the the above screen shots. Some versions of Visual Studio provide other C++ analysis rules from Microsoft that display progress information in the background tasks pop-up window. These messages do not relate to SonarLint analysis. See here or more information on the Microsoft C++ rules.
SonarLint has 450+ rules for C++ and 280+ rules for C. Most run very quickly and will return issues in under a second. However, some of the more advanced rules that involve semantic analysis can take more than ten seconds to run.
Analysis is performed in the background in a separate process. It should not have a noticeable impact on the user experience in Visual Studio. If the analysis is taking too long for a particular file then the analysis process will be terminated. If an analysis is being re-triggered (e.g. via a re-save of the file), the previous analysis will be cancelled and a new analysis will start.
Prior to v4.22, issues were only displayed in the Error List after all rules had finished processing. As of v4.23, issues are displayed in the Error List as soon as they are available. This means that most issues will appear within a few seconds. However, the status bar may still continue to display the analyzing xxx.cpp
message for some time until all of the rules have finished processing.
By default, an analysis that has not completed within one minute will be stopped and a message logged in the Output Window.
We expect such timeouts to be very rare, and probably indicates a problem in one of our analysis rules. If you do encounter timeouts when analysing files, please open an issue in the SonarLint section of the Community Forum and tag it with cfamily
.