Using PVS-Studio with JetBrains Rider

PVS-Studio analyzer can be used with JetBrains Rider IDE as a plugin providing a convenient GUI for analyzing projects and individual files as well as managing diagnostic messages.

PVS-Studio plugin for Rider can be installed from the official JetBrains plugin repository or from the repository on our website. Another way to install it is by using the PVS-Studio installer for Windows, which is available on our download page.

Installing the plugin from the official JetBrains repository

To install PVS-Studio plugin from the official JetBrains repository, open the settings window by clicking 'File -> Settings -> Plugins', choose the Marketplace tab, and enter 'PVS-Studio' in the search bar. The 'PVS-Studio for Rider' plugin will appear in the search results:

https://import.viva64.com/docx/manual/Rider/image1.png

Click 'Install' next to the plugin name. Once the installation is finished, click Restart IDE.

https://import.viva64.com/docx/manual/Rider/image3.png

After restarting the IDE, you can use PVS-Studio plugin to analyze your code.

Installing the plugin from the PVS-Studio repository

In addition to the official JetBrains repository, PVS-Studio plugin for Rider is also available from PVS-Studio's own repository. To install the plug-in from there, you first need to add this repository to Rider IDE. To do this, click on the 'File -> Settings -> Plugins' command to open the plugin installation window.

https://import.viva64.com/docx/manual/Rider/image5.png

In that window, click the gear icon in the top-right corner and select 'Manage Plugin Repositories' in the drop-down list.

https://import.viva64.com/docx/manual/Rider/image7.png

In the opened window, add the http://files.viva64.com/java/pvsstudio-rider-plugins/updatePlugins.xml path, and click OK.

https://import.viva64.com/docx/manual/Rider/image9.png

The final installation step is the same as in the previous scenario of installing the plugin from the official repository: open the Marketplace tab and enter "PVS-Studio" in the search box. Select the plugin 'PVS-Studio for Rider' in the search results, click 'Install', and restart the IDE.

Installing the PVS-Studio C# analyzer

To be able to use PVS-Studio in the Rider IDE, you will also need to install the kernel of the C# analyzer and its dependencies in addition to the plugin itself.

If you have installed the plugin using the PVS-Studio installer for Windows, then all the required components have been already installed on your system, so you can skip this step.

If you have installed the plugin separately (by adding the repository or from the official JetBrains repository), you fist need to download and install the PVS-Studio C# analyzer core for the relevant platform from here.

Entering a license

To enter your PVS-Studio license, open any project in Rider and then open the plugin settings window: 'Tools -> PVS-Studio -> Settings':

https://import.viva64.com/docx/manual/Rider/image10.png

Choose the Registration tab.

https://import.viva64.com/docx/manual/Rider/image11.png

Fill in the 'User Name' and 'Serial Number' fields with the corresponding values from your license.

https://import.viva64.com/docx/manual/Rider/image13.png

If the license you have entered is correct, the 'Invalid License' label will be replaced with 'Valid License' and the license expiration date will appear in the 'Expires' field. Click 'Save' to confirm and save the license.

https://import.viva64.com/docx/manual/Rider/image15.png

Plugin settings

The Settings window of the PVS-Studio plugin comprises several tabs. Let's discuss each in detail.

Settings – settings of the PVS-Studio analyzer core. Hover the mouse pointer over the option name to see a pop-up tooltip for that option.

https://import.viva64.com/docx/manual/Rider/image17.png

Warnings – a list of all the diagnostic rules supported by the analyzer. Unchecking a diagnostic rule prevents all warnings associated with it from being displayed in the analyzer's output window.

https://import.viva64.com/docx/manual/Rider/image19.png

Excludes – contains masks for filenames and paths to be excluded from analysis.

https://import.viva64.com/docx/manual/Rider/image21.png

Registration – contains information about the current license.

https://import.viva64.com/docx/manual/Rider/image23.png

Checking code with PVS-Studio from Rider

JetBrains Rider can open projects in two modes: the project itself, or the project's source folder. When opening a project, Rider can open both individual 'csproj' files, and a solution file containing one or more project files.

With a project or solution opened, you can choose to check:

  • The current project/solution.
  • Items selected in the 'Explorer' window.
  • file currently opened in the code editor.

To analyze the current project or solution, choose the 'Tools -> PVS-Studio -> Check Current Solution/Project' menu item.

https://import.viva64.com/docx/manual/Rider/image24.png

To analyze an opened file, choose the 'Tools -> PVS-Studio -> Check Open File' command.

https://import.viva64.com/docx/manual/Rider/image25.png

You can also select several items in the 'Explorer' window using the CTRL/SHIFT + mouse Left Click and then choose 'Tools -> PVS-Studio -> Check Selected Items' command:

https://import.viva64.com/docx/manual/Rider/image26.png

Another way to do this is to open the drop-down menu by right-clicking in the 'Explorer' window and selecting 'Check Selected Items' menu item:

https://import.viva64.com/docx/manual/Rider/image28.png

In the examples above, all of the *.cs and *.csproj files from the folders Core and Controllers, as well as the Startup.cs file will be analyzed.

When a project folder is opened in Rider, PVS-Studio doesn't know which project, file, or solution exactly should be analyzed, so the 'Check Current Solution/Project' and 'Check Open File' menu items are inactive. The only available option is to check the solution through the 'Tools -> PVS-Studio -> Check Selected Items' command:

https://import.viva64.com/docx/manual/Rider/image29.png

Another way to achieve this is to open the drop-down menu by right-clicking in the 'Explorer' window and selecting 'Check Selected Items' menu item.

https://import.viva64.com/docx/manual/Rider/image31.png

Managing analysis results

The analysis results produced by PVS-Studio analyzer will appear in the table inside the 'PVS-Studio' window:

https://import.viva64.com/docx/manual/Rider/image32.png

The table is made up of 7 columns (from left to right: Favorite, Code, CWE, Message, Position, Projects, False Alarms). The analyzer messages can be sorted by any column. To change the sorting order, click on the column heading. The leftmost column (Favorite) can be used to bookmark warnings for quick search among marked messages by sorting the messages by the Favorite column.

https://import.viva64.com/docx/manual/Rider/image34.png

When clicking on a warning code in the Code / CWE columns, a webpage will open in your browser providing a detailed description of the warning or potential vulnerability. The Message column provides brief descriptions of the warnings. The Position column contains a list of files the warning refers to. The Projects column is a list of projects containing the file the warning refers to. The rightmost column, False Alarms, contains warnings marked as false positives. Managing false positives will be described in detail further, in the corresponding section.

Double clicking on a table row opens a file at the line the warning was triggered at:

https://import.viva64.com/docx/manual/Rider/image35.png

There are also two arrow buttons above the table – these can be used to move between the warnings and open the associated files in the source code editor. To the right of the arrow buttons, a number of filter buttons are available, which allow you to sort the warnings by severity level: High, Medium, Low, and Fails (failures of the analyzer itself).

https://import.viva64.com/docx/manual/Rider/image37.png

When clicking the search icon, an additional panel opens with text fields for searching across the Code, CWE, Message, and Position columns. Each field is a string filter allowing you to filter the messages by the text you have entered.

https://import.viva64.com/docx/manual/Rider/image38.png

The button with three horizontal lines across it can be found in the top-left corner above the table. Clicking it opens an additional settings panel:

https://import.viva64.com/docx/manual/Rider/image40.png

Clicking the gear icon opens the plugin's settings main window, which is also available at 'Tools -> PVS-Studio -> Settings'.

Managing false positives

Sometimes you may get a warning pointing out some spot in your code, but you know that there is no error in that spot. Such a warning is called a false positive.

PVS-Studio Rider plugin allows you to mark the analyzer's messages as false positives to prevent them from appearing in future checks.

To mark false positives, select one or more warnings in the 'PVS-Studio' table, right-click on any row to open the drop-down menu, and select the 'Mark selected messages as False Alarms' command:

https://import.viva64.com/docx/manual/Rider/image41.png

The analyzer will add a special comment of the '\\-Vxxx' pattern to the line the warning has been triggered by, where xxx is the PVS-Studio's diagnostic number. You can also add such comments manually.

To have previously marked false warnings displayed in the table, enable the 'Show False Alarms' option at 'Tools -> PVS-Studio -> Settings':

https://import.viva64.com/docx/manual/Rider/image43.png

Use the 'Remove False Alarm marks from selected messages' drop-down menu item to unmark selected warnings as false positives.

To learn more about suppressing analyzer-generated warnings and other ways of suppressing warnings by using configuration files (.pvsconfig) added to the project, see the Suppression of false alarms documentation section.

Suppressing analyzer warnings in legacy code

Getting started with static analysis and using it regularly may be difficult due to multiple warnings triggered by legacy code. Such code is typically well tested and stable, so fixing every warning in it isn't necessary – all the more so because if the code base is large, fixing it may take a long time. What's more, warnings issued on legacy code prevent you from focusing on warnings issued on newly written code still in development.

To solve this problem and start using static analysis regularly without delay, PVS-Studio allows you to "turn off" warnings in the legacy code. To do that, select 'Tools -> PVS-Studio -> Suppress All Messages' command or click the 'Suppress All Messages' button on the PVS-Studio window toolbar. After that, all messages will be added to special *.suppress files, which is what the suppression mechanism is based on. The next time you run the analysis, the warnings added to these *.suppress files will be excluded from the analyzer's report. This suppression mechanism is quite flexible and is able to "track" suppressed messages even after you modify or move the involved code fragments.

The *.suppress files are created at the project level, in the same location where the project file is stored, but you can also add them to any project or solution (for example, if you want to use one suppress file for several projects or an entire solution). To get those warnings back in the report, delete the suppress files associated with the affected projects.

To learn more about warning suppression and to see the guide on handling *.suppress files, see the Mass suppression of analyzer warnings documentation section.

Drop-down menu of the warnings table

Right-clicking on a warning in the PVS-Studio window table opens a drop-down menu, which contains additional items for managing selected warnings.

Clicking the 'Mark selected messages as False Alarms / Remove false alarm masks' item marks selected warnings as false positives by adding a special comment to the lines of code they refer to (see the section above on managing false positives).

The 'Exclude from analysis' item is used to add the full or partial pathname of the file containing a warning to the list of folders excluded from analysis. Every file whose pathname matches the filter will be excluded from the analysis.

https://import.viva64.com/docx/manual/Rider/image45.png

Saving and loading analysis results

Analysis results can be saved or loaded using the items of the 'Tools -> PVS-Studio' submenu:

https://import.viva64.com/docx/manual/Rider/image47.png

The 'Open Report' command opens the .json report file and loads its contents into the table in the 'PVS-Studio' output window.

The 'Recent Reports' submenu contains a list of recently opened reports. Clicking an item on this list opens that file (given that it still exists at that location) and loads its contents into the table in the 'PVS-Studio' window.

Selecting the 'Save Report' item saves all the messages from the table (even the filtered ones) to a .json report file. If the current list of messages has never been saved before, you will be prompted for a name and location to store the report file to.

Similarly, the 'Save Report As' item is used to save all the warnings from the table (even the filtered ones) to a .json file and always prompts you to specify the location to store the report file to.


Bugs Found

Checked Projects
409
Collected Errors
14 072
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →
Accept