Beta testing of PVS-Studio plugin for JetBrains CLion

Traditionally, the main development environment for working with the PVS-Studio analyzer was the Visual Studio environment from Microsoft. Our analyzer started out on Windows, so the choice of Visual Studio was quite justified and obvious. Nevertheless, over more than 10 years of PVS-Studio development, the analyzer has become available for several other languages ​​and platforms, so it is quite natural that more and more people in our support ask about the possibility of integrating PVS-Studio with their favorite IDE.

A year ago, on June 18, 2020, the first release of the PVS-Studio plugin for the JetBrains Rider development environment took place. This release was timed to coincide with the release of the PVS-Studio analyzer for C # on Linux and macOS platforms.

Today we are pleased to announce the beginning of public beta testing of a plugin for another IDE from JetBrains – CLion. We believe that this innovation will significantly improve the experience of working with our product for Linux and cross-platform C ++ users. Based on the results of passing beta tests, we hope to release the first version of the CLion plugin in the upcoming release of PVS-Studio 7.14, in the last days of July – early August.

How to take part in the PVS-Studio for CLion beta test

To fully test the plugin, you need to install the plugin beta itself and the beta version of the C ++ analyzer core. The plugin can be installed in several ways: from the official repository, from the repository on our website, or using the Windows installer of PVS-Studio – below we will tell you how to do it.

After installing the plugin and analyzer, you can register for the PVS-Studio for CLion beta test on our early access page, you will receive a trial key for the analyzer by e-mail.

Detailed documentation on installing and working with PVS-Studio plugins for CLion and Rider can be found here, and then we will give a brief instruction on how to install and launch PVS-Studio for the first time in CLion.

The purpose of any beta test is to collect user feedback on a new product, its usability and, of course, the inevitable bugs that are always present in earlier versions. This beta test is no exception. If you have encountered one of these errors or just want to share your impressions of the new PVS-Studio plugin, be sure to write to us in response to the letter you received after registering for the beta test or contact us using our feedback forms

Installing from the official repository

To do this, start CLion and then File-> Settings-> Plugins, select the Marketplace tab, and enter ‘PVS-Studio’ in the search bar. Next, install the PVS-Studio for CLion plugin.

0839_CLion_beta_test_ru / image2.png

Installing a plugin from the PVS-Studio repository

This point is similar to the previous one, but first you need to configure CLion for the new repository. To do this, go to File-> Settings-> Plugins, click on the “gear” on the right side of the window and select Manage Plugin Repositories in the drop-down menu.

0839_CLion_beta_test_ru / image4.png

In the window that opens, add the path http://files.viva64.com/java/pvsstudio-clion-plugins/updatePlugins.xml… And click OK.

0839_CLion_beta_test_ru / image5.png

Next, install the plugin in the same way as in the previous paragraph.

Installation using Windows installer

If you are using Windows operating system, you can install the plugin and the analyzer core from the distribution kit. To do this, download and run the installer from here (in the table in the Windows column download the “.exe” installer file).

Installing the beta version of the C ++ analyzer

For PVS-Studio to work correctly in CLion, in addition to the plugin itself, you need to install the C ++ analyzer core. To do this, you can go to address and download the distribution for your platform. If you have installed a distribution kit for Windows, then you can skip this item.

If you are using Linux or macOS operating systems, you can also use the following commands to install:

For debian-based systems:

wget -q -O - https://files.viva64.com/beta/etc/pubkey.txt | 
  sudo apt-key add -

sudo wget -O /etc/apt/sources.list.d/viva64-beta.list 
  https://files.viva64.com/beta/etc/viva64.list

sudo apt-get update
sudo apt-get install pvs-studio

For yum-based systems:

wget -O /etc/yum.repos.d/viva64-beta.repo 
  https://files.viva64.com/beta/etc/viva64.repo

yum update
yum install pvs-studio

For zypper-based systems:

wget -q -O /tmp/viva64-beta.key https://files.viva64.com/beta/etc/pubkey.txt
sudo rpm --import /tmp/viva64-beta.key
sudo zypper ar -f https://files.viva64.com/beta/rpm viva64-beta
sudo zypper update
sudo zypper install pvs-studio

For macOS:

brew install viva64/pvs-studio/pvs-studio-beta

Product registration

After registering for the beta test and receiving the registration key, to activate the license, go to the Tools-> PVS-Studio-> Settings window. In the window that opens, go to the Registration tab.

0839_CLion_beta_test_ru / image7.png

In the User Name and Serial Number fields, you must enter the appropriate license information. We remind you once again that you can get the registration key here: early access page

First acquaintance with the plugin

After installation and configuration, the plugin will look something like the image below.

0839_CLion_beta_test_ru / image9.png

The plugin allows you to analyze CMake projects loaded into CLion and individual selected files.

To start the analysis, select Tools-> PVS-Studio-> Check Project.

0839_CLion_beta_test_ru / image10.png

To analyze the selected files, Tools -> PVS-Studio -> Check Current File.

0839_CLion_beta_test_ru / image11.png

The analysis results can be seen in the PVS-Studio window:

0839_CLion_beta_test_ru / image13.png

In the window, you can see a table that consists of columns with a warning code, problem description, position, etc.

When you right-click on the line with the analyzer message in the PVS-Studio window table, a context menu will open containing additional commands for the selected analyzer messages.

The ‘Mark selected messages as False Alarms / Remove false alarm masks’ command allows you to mark the analyzer message as a false alarm by adding a special comment to the code for which the warning was issued.

The ‘Exclude from analysis’ command allows you to add the path or part of the path to the file in which the analyzer warning was found to the list of directories excluded from analysis. All files whose paths fall under this filter will be excluded from the analysis.

0839_CLion_beta_test_ru / image15.png

Double-clicking the left mouse button on the line will open the file on the line where the analyzer warning was found.

0839_CLion_beta_test_ru / image17.png

Plugin settings

To open the plugin settings window, go to Tools-> PVS-Studio-> Settings. The plugin settings panel consists of several tabs. Let’s consider each of them in more detail.

Settings – settings of the PVS-Studio analyzer core. When you hover the mouse cursor over the name of a setting, a tooltip appears describing what the setting is intended for.

0839_CLion_beta_test_ru / image19.png

Warnings – a list of the types of all warnings supported by the analyzer. If you uncheck the warning box, then all warnings of this type in the output table of the analyzer’s work will be filtered:

0839_CLion_beta_test_ru / image21.png

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

0839_CLion_beta_test_ru / image23.png

How to start using the analyzer on a project with a large amount of legacy code

Very often, starting to regularly use static analysis is hampered by numerous triggers on legacy code. Such code is usually already well tested and works stably, so it may not be advisable to edit all the analyzer triggers in it. Moreover, if the size of the codebase is large enough, such an edit can take a long time. At the same time, such messages to the existing code prevent you from looking at messages to the new code that is still in development.

To solve this problem and start using static analysis on a regular basis right away, PVS-Studio offers the ability to “disable” messages in the old code. To suppress analyzer messages on the old code, you can use the ‘Tools -> PVS-Studio -> Suppress All Messages’ main menu command or the ‘Suppress All Messages’ button on the PVS-Studio window panel. The suppression mechanism works with the help of special suppress files, to which the suppressed messages of the analyzer are added after the ‘Suppress All Messages’ command has been executed. At the next start of the analysis, all messages added to such suppress files will not be included in the analyzer report. The suppression system through suppress files is flexible enough and is able to “track” suppressed messages even when modifying and shifting code sections in which the suppressed message is issued.

0839_CLion_beta_test_ru / image24.png

In CLion, suppressed messages are added to suppress_base.json, which is written to the .PVS-Studio directory in the root directory of the project opened in CLion. To return all messages to the analyzer output, you must delete this file and restart the analysis.

See also the article “How to implement a static code analyzer in a legacy project and not demotivate the team“.

Saving and Loading Analysis Results

To save or load the results of the analyzer’s work, you can use the main menu commands available through ‘Tools -> PVS-Studio’:

0839_CLion_beta_test_ru / image26.png

The ‘Open Report’ command opens a .json report file and loads its contents into the table of the ‘PVS-Studio’ window.

The ‘Recent Reports’ submenu shows a list of the several most recently opened report files. When you click on an item in the list, the corresponding report will be opened (if the report still exists along this path) and its contents will be loaded into the table of the ‘PVS-Studio’ window.

The ‘Save Report’ command saves all messages from the table (even filtered ones) to a .json report file. If the current analysis result has never been saved, you will be prompted to specify a name and location for saving the report.

Likewise, the ‘Save Report As’ command saves all warnings from the table (even filtered ones) to a .json report file, always prompting you to select a location to save the report on disk.

Incremental analysis

We usually recommend that you run a full analysis regularly, for example, once a day, at night. However, to maximize the effect of using the analyzer, in addition to nightly analysis, you can check new code immediately after it is written. To do this, you can use incremental analysis, which works as follows. After the changes have been made to the project, the developer starts the build, and after the successful completion of the compilation, only the changed files will be analyzed. Modified files are those files that have changed since the previous analysis.

Incremental analysis mode can be enabled or disabled. To do this, select the Tools-> PVS-Studio-> Analysis after Build (Modified files only) option and then Enabled or Disabled.

0839_CLion_beta_test_ru / image27.png

Conclusion

With the support of the new JetBrains CLion IDE, we hope to make the use of the analyzer more convenient for our C ++ users on all supported platforms (Windows, Linux, macOS). And although there are still many development environments that do not have direct PVS-Studio integration (however, in many of them you can use the analyzer using standard compiler warning viewers), we plan to increase the number of IDEs that we support directly in the future.

Based on the interest of our users, the most likely next candidate for such support would be Visual Studio Code. Write to us if you are interested in direct integration of our analyzer into “your” IDE, and perhaps it will also appear in our plans.

Well, in the end, let me remind you once again that you you can register to participate in the beta test and Write to us through the feedback form about the problems and wishes found.

If you want to share this article with an English-speaking audience, please use the translation link: Beta-Testing of PVS-Studio Plugin for JetBrains CLion.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *