Logo

dev-resources.site

for different kinds of informations.

CodeChecker - code quality control using PVS-Studio

Published at
12/13/2024
Categories
programming
code
Author
pvsdev
Categories
2 categories in total
programming
open
code
open
Author
6 person written this
pvsdev
open
CodeChecker - code quality control using PVS-Studio

CodeChecker is a popular open-source quality control tool on Linux and macOS. In this short post, we will tell you how to use it with the PVS-Studio analyzer.

1197_codechecker/image1.png

CodeChecker is written in Python and supports many code analyzers for various languages. Some of the pros of this tool include ease of use and the straightforward installation process. CodeChecker has supported the PVS-Studio analyzer quite recently. Therefore, we're writing this article guide readers through the installation process and demonstrate how to use the tool with the PVS-Studio static code analyzer.

CodeChecker installation

In order to use CodeChecker, we need a Python interpreter of the 3.8 version or later. The tool is distributed as a Python package, so we'll need to run a few simple commands to install it.

First, create a Python virtual environment, then install the codechecker package and start the server.

For example, here are the commands for Linux:

python3 -m venv .venv
source ./venv/bin/activate
pip3 install codechecker
Enter fullscreen mode Exit fullscreen mode

The PVS-Studio analyzer support in the built-in report-converter tool will appear in the CodeChecker 6.25.0 version, but you can use PVS-Studio with CodeChecker now. To do this, clone the tool source code from the GitHub repository and then install the latest version of the report-converter component from the repository into the virtual environment that was created in the previous step:

cd tools/report-converter/
python setup.py install
Enter fullscreen mode Exit fullscreen mode

Next, download the codechecker.json file and save it where CodeChecker is installed. This will help display PVS-Studio diagnostic rule levels correctly. In the case of our example, this is the directory: .venv/share/codechecker/config/labels/analyzers. In the directory, change the file name to pvs-studio.json.

After that, run the following command to start the CodeChecker server:

CodeChecker server
Enter fullscreen mode Exit fullscreen mode

By default, the CodeChecker server locates by the http://localhost:8001 address. Right after the run, a usable product will be created.

1197_codechecker/image2.png

Report conversion

CodeChecker uses its own report format. You must convert the PVS-Studio analyzer report into it. CodeChecker's built-in tool—report-converter—will help you with this. You can pass the PVS-Studio .json report to it using the following command:

report-converter -t pvs-studio -o ./pvs_studio_reports ./PVS-Studio.json
Enter fullscreen mode Exit fullscreen mode

The -t flag specifies the analyzer report that we want to convert. The -o flag indicates the directory where report-converter will save the converted report. The last parameter is the path to the PVS-Studio report.

If the PVS-Studio report is not saved in the .json format, you can convert it using the plog-converter utility with the following command:

plog-converter -t json -a 'GA:1,2;OWASP:1' 
   -o /home/user/Logs/PVS-Studio.json PVS-Studio.log
Enter fullscreen mode Exit fullscreen mode

The -t flag indicates the report format after conversion, -a defines the groups of PVS-Studio diagnostic rules that should be left in the output report, -o sets the path to save the converted report. The last parameter is the path to the report to be converted.

After the PVS-Studio report is converted into the CodeChecker format, save it to the server. To do this, run the following command:

CodeChecker store ./pvs_studio_reports -n default
Enter fullscreen mode Exit fullscreen mode

After the -n flag, pass the name of the CodeChecker run. When this command is executed, a run named default appears on our default product page.

1197_codechecker/image3.png

Viewing the report

Now you can view and handle the analyzer warnings. To see the full list of warnings, click on the warning, and you'll get the list like this:

1197_codechecker/image4.png

Warnings in CodeChecker are divided into different levels:

  • Unspecified
  • Low
  • Medium
  • High
  • Critical
  • Style.

The PVS-Studio analyzer warnings are classified as Low, Medium, and High. This helps adhere to the general classification of PVS-Studio warnings across different tools. Messages about errors in the analyzer's operation fall into the Unspecified category.

Note. Let's say all the warnings in the list are Unspecified. Then, save the file with PVS-Studio diagnostic level markup to the directory with the CodeChecker installation location. The above section "CodeChecker Installation" explains it.

Due to CodeChecker web interface, the analyzer warnings can be filtered by a variety of parameters: the certainty level, diagnostic rule name, etc. Click on a specific warning, and you will see the place in the code where the bug lurks.

1197_codechecker/image5.png

CodeChecker enables you to markup warnings by setting a Review status of a particular warning. You can set one the following statuses to each warning:

  • Confirmed bug—the warning is true and needs to be fixed;
  • False positive—the warning is false;
  • Intentional—the warning is true but doesn't require fixing.

If you set False positive to a warning, it will no longer appear in the list, as well as in all future runs. Also, when changing a warning status, you can leave a comment, for example, about how quickly one can fix this error.

With each follow-up run, new warnings appear with a special sign. There's another handy way to view warnings that appear between the runs. Select two runs from the menu and click on the checkboxes.

1197_codechecker/image6.png

After clicking the Diff button, you'll see only the warnings that appeared on a fresh run:

1197_codechecker/image7.png

Summary

Keeping code clean and neat is an important task, which requires the best tools. CodeChecker is a really convenient interface for viewing and marking warnings of analyzers, including PVS-Studio. You can read more about using the PVS-Studio analyzer in CodeChecker in the documentation.

Besides CodeChecker, the PVS-Studio static analyzer integrates into such code quality control systems as SonarQube and DefectDojo. You're welcome to try PVS-Studio by the link.

code Article's
30 articles in total
Favicon
Day 1081 : Prototype
Favicon
Day 1080 : Tuff
Favicon
From Chaos to Clarity: Formatting React Code for a Clean and Readable Codebase
Favicon
Day 1079 : Price I'll Pay
Favicon
Dynamic Pivot Points with Crossup Optimization System
Favicon
2024 Recap; 2025 Goals
Favicon
Day 1078 : Proceed
Favicon
Day 1077 : Working On It
Favicon
Price Pattern Based Double Bottom and Top Automated Trading Strategy
Favicon
Day 1076 : Life in 3D
Favicon
Day 1075 : Happy New Year
Favicon
How to Conduct Effective Code Reviews
Favicon
Switch Case
Favicon
hormones for Artificial Intelligence
Favicon
Find Largest Value in Each Tree Row
Favicon
Using ASTs to merge LLM generated snippets in to existing code files with surgical precision.
Favicon
Discount Promo Code for Top Stores - Save Big Today!
Favicon
Redefining Success with the Best IT Company in Mohali
Favicon
Hello everyone. I need some advice , I am looking for mentor to help go through coding journey to get first job. I am living un UK at the moment , moved back in three years to Poland. I have tried myself, and purchased Jonas JavaScript and React tutorials.
Favicon
33rd day of my CP journey
Favicon
55th day of my CP journey
Favicon
51st day of my CP journey
Favicon
✨ CSS bits: Smooth Scroll Animations with scroll-behavior
Favicon
Top Snapseed QR Codes for Amazing Photo Edits
Favicon
Average Reads and PyLadiesCon 2024
Favicon
Annotations: Java's Hidden Weapons ⚔️
Favicon
CodeChecker - code quality control using PVS-Studio
Favicon
angular and json
Favicon
Day 1073 : Running Wild
Favicon
The Ultimate Guide to iOS Development: From Programming Basics to Building Your First App (Part 2)

Featured ones: