Our website uses cookies to enhance your browsing experience.
Accept
to the top
close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
** By clicking this button you agree to our Privacy Policy statement
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
* By clicking this button you agree to our Privacy Policy statement

close form
Free PVS‑Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

close form
To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

close form
I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam

Webinar: Evaluation - 05.12

>
>
Excluding files and directories from an…
menu mobile close menu
Analyzer diagnostics
General Analysis (C++)
General Analysis (C#)
General Analysis (Java)
Micro-Optimizations (C++)
Diagnosis of 64-bit errors (Viva64, C++)
Customer specific requests (C++)
MISRA errors
AUTOSAR errors
OWASP errors (C++)
OWASP errors (C#)
Problems related to code analyzer
Additional information
toggle menu Contents

Excluding files and directories from analysis

Oct 27 2022

When checking your projects that use many third-party libraries, you may need to focus on certain potential problems in your code. For such purposes, PVS-Studio tools provide a mechanism that excludes files from analysis. The mechanism allows you not only to decrease the number of unnecessary warnings, but also to significantly speed up the analysis of your project.

Excluding files via IDE settings

Visual Studio and C and C++ Compiler Monitoring UI

In Visual Studio, open the settings of the plugin Extensions -> PVS-Studio -> Options -> Don't Check Files.

If use the C and C++ Compiler Monitoring UI utility, open Tools -> Option... -> Don't Check Files.

In the window that appears, you can specify the files and directories to be excluded from the analysis. You can also use wildcard masks.

Exclude_paths/image1.png

Note that not all masks in the Visual Studio plugin can be applied to filter an existing report. If the mask is not applicable for filtering, you will receive a message stating that you need to restart analysis to apply the mask. Masks with the '*' character at the beginning and/or at the end are immediately applied to filter warnings in the plugin table.

You can read more about excluding files via the plugin settings for Visual Studio here.

You can also exclude files from analysis via the context menu in the analyzer's report. To do this, right click on the warning and select 'Don't check files and hide all messages from...'. In the drop-down menu, you can select the nesting level of directories from which files should be excluded.

Exclude_paths/image2.png

Note that information about excluded directories and files is written to the global Settings.xml file. That information can be used by other PVS-Studio tools if the path for the settings file is not passed to them.

Plugins for CLion and Rider

To exclude files or directories from analysis, open the PVS-Studio plugin settings (Tools -> PVS-Studio -> Settings) and select the Excludes section.

Exclude_paths/image4.png

In this section, you can manage the paths and masks of file names that will be excluded from the analysis.

You can also exclude a file or a directory from the analysis directly through the context menu of the PVS-Studio report. To do this, right-click on the message and select 'Exclude From Analysis'. In the drop-down menu, you can select the nesting level of directories from which files should be excluded.

Exclude_paths/image5.png

Note that information about excluded directories and files is written to the global Settings.xml file. That information can be used by other PVS-Studio tools if the path for the alternative settings file is not passed to them.

Excluding files via the Settings.xml file

Console tools can use either the global Settings.xml file or a specific one passed as a command line argument. A specific file can be useful if you have specific analysis settings for a project which should not affect the analysis results of other projects. For example, a list of excluded directories.

To create an alternative settings file, copy the Settings.xml file from the '%APPDATA%/PVS-Studio/' (Windows) or '~/.config/PVS-Studio' (Linux) directory to any place (for example, to the directory of the project being checked). Then add the excluded files and directories to the ApplicationSettings/PathMasks node (if it is a directory) or to ApplicationSettings/FileMasks (if it is a file).

For example:

<ApplicationSettings ...>
  ...
  <PathMasks>
  ...
     <string>\EU*\Engine\Source</string>
  </PathMasks>
  ...
</ApplicationSettings>

Now, use the ‑‑settings (-s) parameter to pass your custom settings file to PVS-Studio_Cmd.exe or pvs-studio-dotnet (Linux and macOS):

PVS-Studio_Cmd.exe -t ProjName.sln -s /path/to/NonDefaultSettings.xml

To pass the parameter to CLMonitor.exe use the ‑‑settings (-t) flag in any launch mode:

CLMonitor.exe monitor -t /path/to/NonDefaultSettings.xml

Excluding files via the diagnostic configuration file (.pvsconfig)

You can create a file — .pvsconfig (analyzer diagnostics configuration file). In this file, you can use special comments to describe the files and directories to be excluded from analysis. Read more about the .pvsconfig file here.

To exclude a file or directory from analysis, all you need to do is specify its path or path mask — use the special //V_EXCLUDE_PATH comment.

For example:

//V_EXCLUDE_PATH C:\TheBestProject\ThirdParty
//V_EXCLUDE_PATH *\UE*\Engine\Source\*
//V_EXCLUDE_PATH *.autogen.cs

Now you can use the .pvsconfig file with PVS-Studio utilities:

For CLMonitor.exe, use the -c (‑‑pvsconfig) flag:

CLMonitor.exe analyze ... -c /path/to/.pvsconfig

For PVS-Studio_Cmd.exe and pvs-studio-dotnet, use the -C (‑‑rulesConfig) flag:

PVS-Studio_Cmd.exe -t target.sln -o PVS-Studio.log -C /path/to/.pvsconfig
pvs-studio-dotnet -t target.csproj -o PVS-Studio.log -C /path/to/.pvsconfig

For CompilerCommandsAnalyzer.exe (Windows) and pvs-studio-analyzer (Linux, macOS), use the -R (‑‑rules-config) flag:

CompilerCommandsAnalyzer analyze --cfg /path/to/PVS-Studio.cfg \
                                    -R /path/to/.pvsconfig

If you use the C and C++ Compiler Monitoring UI utility, you can specify the path to the .pvsconfig file when you start monitoring:

Exclude_paths/image6.png

PVS-Studio plugins (for Visual Studio, Rider) can automatically detect the .pvsconfig file if it is added to the Solution or project and has the .pvsconfig extension. Configuration files added to the Solution have a global scope and apply to all projects of this Solution. .pvsconfig files added to the project apply only to the project to which they are added.

For CompilerCommandsAnalyzer.exe and pvs-studio-analyzer utilities

If you use the pvs-studio-analyzer(Linux, macOS) / CompilerCommandsAnalyzer.exe (Windows) cross-platform utility, you can exclude files from analysis in the following ways.

Direct pass of excluded files and directories

You can exclude files from analysis by passing paths to them as launch arguments for pvs-studio-analyzer/CompilerCommandsAnalyzer.exe via the -e (‑‑exclude-path) flag:

pvs-studio-analyzer analyze ... -e /third-party/ \
                                -e /test/        \
                                -e /path/to*/exclude-path

When specifying a path, you can also use command shell templates (glob).

The *.cfg configuration file

Create a text file (for example, MyProject.cfg). Put a list of excluded directories in the text file via the exclude-path parameter.

Example:

exclude-path=/third-party/
exclude-path=*/test/*
exclude-path=*/lib-*/*

Then run the analysis by passing the path to the configuration file via the ‑‑cfg flag:

pvs-studio-analyzer analyze ... --cfg ./MyProject.cfg

You can also add other launch parameters to the configuration file. Check out this page to get more information.