A plugin for JetBrains IDEs to provide inspections for C/C++ files utilizing the static analyzer Cppcheck.
This project is supported with a free open source license of CLion from JetBrains.
- Runs
Cppcheck
on the fly while you write code. - Highlights lines and displays
Cppcheck
error messages. - Supports passing options to
Cppcheck
.
-
Install the
cppcheck
plugin from the JetBrains Marketplace: https://plugins.jetbrains.com/plugin/8143-cppcheck. See Installing, Updating and Uninstalling Repository Plugins for more details. -
Install Cppcheck. Please refer to https://github.com/danmar/cppcheck#packages on how to obtain a version of Cppcheck for your platform.
-
Go to the
Cppcheck Configuration
section in the settings of your respective JetBrains IDE and put the absolute path to the Cppcheck executable in theCppcheck Path
. -
(Windows) The executable is found in the path you specified during the installation. By default this should be
C:\Program Files\Cppcheck\cppcheck.exe
. -
(Non-Windows) Use
which cppcheck
orcommand -v cppcheck
on the command-line to get the location of the executable. The default depends on your system but should usually be/usr/bin/cppcheck
or/usr/local/bin/cppcheck
.
The plugin provides the Show Cppcheck XML Output
action which will show the raw XML output of the latest finished analysis.
The verbose level of the plugin. The following additional information are provided:
0
- no verbose information
1
- a notification will be shown if the analysis finished
2
- a notification will be shown if the analysis was invoked (includes all command-line options)
4
- a notification will be shown for each findings in the result (will not show the internally ignored ones)
See https://github.com/johnthagen/clion-cppcheck/issues for a complete list of tracked issues and enhancements requests.
Cppcheck is not designed to be run on header files (.h
) directly, as must be done for this
plugin, and as a result may have false positives.
When run on header files directly, Cppcheck defaults to C as the language, which will generate
false positives for C++ projects. So --language=c++
is implicitly added as option when analyzing header files.
It will also provide unusedFunction
and unusedStructMember
false positives so these findings are being suppressed.
By default Cppcheck tries to determine all the available configurations for a file (i.e. all combination of the used
preprocessor defines). As the plugin doesn't get the current list of defines this may lead to findings shown in code
which is shown as disabled in the editor. To check just a specific configuration you can either add defines using -D
to the options. Or you can limit the configurations to a single one adding --max-configs=1
.
By default Limiting the configurations also decreases the time of the analysis.
By default a maximum of 12 configurations is checked. This may lead to some code which might actually be active not to
show any findings. This can also be controlled by the --max-configs=<n>
option.
No additional includes path are being passed to Cppcheck for the analysis which might result in false positives or not all findings being shown.
You can add additional include path using the -I <path>
options.
The batch analysis passes the files individually to Cppcheck just like the highlighting inspections. So if you pass a
folder to the batch analysis it might not show the same findings as when passing a folder to Cppcheck
itself.
It will also pass all the contents of the folder to the analysis and not just project files. This might lead to unexpected findings.
Also some findings in headers files triggered by the analysis of a source files are not being shown.
Related issues:
#54
Show Cppcheck XML Output
only shows the XML result of the latest analysis. If you need to view the results for a
specific file make sure it was the last one analyzed.
Related issues:
#53
Cppcheck does not support analyzing of external library or system includes. It provides profiles for several external
libraries which describe the contents and behavior of the includes which allows it to finding issues with usage of them
in the code. To add such a profile to your analysis you need to specify it via the --library=<name>
option. The
available profile can be found in the cfg
folder of your Cppcheck
installation.
Currently the configured options are global and not per project.
Related issues:
#52
To run the plugin from source, open this project in IntelliJ and create a new "Plugin" run configuration. Running or debugging this run configuration will launch a new IntelliJ process with the plugin loaded into it.
See this page for details: https://jetbrains.org/intellij/sdk/docs/basics/getting_started/setting_up_environment.html
To build the plugin for deployment to the https://plugins.jetbrains.com/, select Build | Prepare Plugin Module For Deployment.
- @johnthagen
- @firewave
- Removed
com.intellij.modules.java
dependency. - Bumped the oldest supported product versions to 2020.1.
- Added missing
com.intellij.modules.java
dependency.
- Added
Show Cppcheck XML Output
action to show the latest XML output. - Report execution errors as global inspection errors.
- Display
Cppcheck Path
configuration errors as global inspection errors instead of using a (hard to spot) status bar message. - Display global inspection error and omit the option if the configured
MISRA Addon JSON
does not exist. - Made plugin verbose level configurable via settings.
- Display all available details for findings in tooltip.
- Fixed
NullPointerException
with Cppcheck < 1.89 caused by missingcolumn
attribute in XML result.
- Fixed missing
commons-lang3
dependency. - Fixed
.idea
project provided by repository.
- Parse
--xml
output instead of text output. (Contribution by @firewave) - Fixed scanning of files with whitespaces in name. (Contribution by @firewave)
- Only scan files which actually exist. (Contribution by @firewave)
- Use unique file names for temporary files used for analysis. (Contribution by @firewave)
- Properly handle
debug
messages generated by--debug-warnings
. (Contribution by @firewave) - Added
.cl
,.hxx
,.tpp
and.txx
to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave) - Internally suppress
unusedFunction
andunusedStructMember
(for header files only) warnings to avoid false positives. (Contribution by @firewave) - Fixed
information
messages not being shown at all. (Contribution by @firewave)
Improved reporting of execution failures. (Contribution by @firewave)
- Correctly specify minimum supported CLion version.
- Support showing inconclusive annotations in the IDE. (Contribution by @firewave)
Fix NullPointerException. (Contribution by @firewave)
Fix NullPointerException. (Contribution by @firewave)
Support Cppcheck MISRA addon. (Contribution by @SJ-Innovation)
Support Cppcheck >1.89. (Contribution by @SJ-Innovation)
Greatly improve plugin responsiveness to changes by using virtual files to interact with Cppcheck. (Contribution by @fastasturtle)
Use CapturingProcessHandler
to fix read locking issues and spaces in path to source files.
(Contribution by @fastasturtle)
Fix formatting on plugin homepage.
Improve the user's guide for installing and using the plugin. Default to using --language=c++
Cppcheck option.
Fix handling Cppcheck errors that span multiple lines.
Avoid drawing errors in .cpp and .c files from header files they import.
Fix NullPointerException when opening files with no extension.
Add warning about header file false positives in C++ projects.
Fix highlighting prepended whitespace.
Highlight line corresponding to severity.
Fix execution on Linux.
Fix possible out of bounds line number when Cppcheck gets out of sync with in-memory file.
First release.