|
1 |
| -# CLion-cppcheck |
| 1 | +# clion-cppcheck |
2 | 2 |
|
3 |
| -- Runs `cppcheck` on the fly while you write code. |
4 |
| -- Highlights lines and displays `cppcheck` error messages. |
5 |
| -- Supports passing options to `cppcheck`. |
| 3 | +A plugin for JetBrains IDEs to provide inspections for C/C++ files utilizing the static analyzer [Cppcheck](https://cppcheck.sourceforge.io/). |
6 | 4 |
|
7 | 5 | This project is supported with a free open source license of CLion from
|
8 | 6 | [JetBrains](https://www.jetbrains.com/?from=clion-cppcheck).
|
9 | 7 |
|
| 8 | +## Features |
| 9 | + |
| 10 | +- Runs `Cppcheck` on the fly while you write code. |
| 11 | +- Highlights lines and displays `Cppcheck` error messages. |
| 12 | +- Supports passing options to `Cppcheck`. |
| 13 | + |
10 | 14 | ## Installation
|
11 | 15 |
|
12 |
| -See |
13 |
| -[Installing, Updating and Uninstalling Repository Plugins](https://www.jetbrains.com/help/clion/managing-plugins.html) |
| 16 | +- Install the `cppcheck` plugin from the JetBrains Marketplace: https://plugins.jetbrains.com/plugin/8143-cppcheck. See |
| 17 | +[Installing, Updating and Uninstalling Repository Plugins](https://www.jetbrains.com/help/clion/managing-plugins.html) for more details. |
| 18 | + |
| 19 | +- Install Cppcheck. Please refer to https://github.com/danmar/cppcheck#packages on how to obtain a version of Cppcheck for your platform. |
14 | 20 |
|
15 |
| -- [`cppcheck` in JetBrains Plugin Repository][cppcheck_plugin] |
| 21 | +- Go to the `Cppcheck Configuration` section in the settings of your respective JetBrains IDE and put the **absolute** path to the Cppcheck executable in the `Cppcheck Path`. |
| 22 | + |
| 23 | +- (Windows) The executable is found in the path you specified during the installation. By default this should be `C:\Program Files\Cppcheck\cppcheck.exe`. |
| 24 | +- (Non-Windows) Use `which cppcheck` or `command -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`. |
16 | 25 |
|
17 | 26 | ## Usage
|
18 | 27 |
|
19 |
| -1. Install the [`cppcheck`](http://cppcheck.sourceforge.net/) tool using the instructions on its homepage. This plugin |
20 |
| - does **not** bundle the `cppcheck` tool itself, which must be installed separately. |
21 |
| -2. Install the [cppcheck plugin][cppcheck_plugin] into CLion. |
22 |
| -3. Configure the plugin with the **absolute** path to the `cppcheck` executable into the `cppcheck path` option. |
23 |
| - 1. Windows |
24 |
| - 1. File | Settings | Cppcheck configuration |
25 |
| - 2. Usually the path is `C:\Program Files (x86)\Cppcheck\cppcheck.exe` |
26 |
| - 2. macOS: |
27 |
| - 1. CLion | Preferences | Cppcheck configuration |
28 |
| - 2. In a terminal run `which cppcheck` to find the path to `cppcheck`. If you installed it with |
29 |
| - [Homebrew](https://brew.sh/), the path will be `/usr/local/bin/cppcheck`. |
30 |
| - 3. Linux |
31 |
| - 1. File | Settings | Cppcheck configuration |
32 |
| - 2. In a terminal run `which cppcheck` to find the path to `cppcheck`. If you installed it with your |
33 |
| - system's package manager, it is probably located at `/usr/bin/cppcheck`. |
34 |
| - |
35 |
| -[cppcheck_plugin]: https://plugins.jetbrains.com/plugin/8143 |
36 |
| - |
37 |
| -## Known Issues |
38 |
| - |
39 |
| -`cppcheck` is not designed to be run on header files (`.h`) directly, as must be done for this |
| 28 | +### Provided Actions |
| 29 | + |
| 30 | +The plugin provides the `Show Cppcheck XML Output` action which will show the raw XML output of the latest finished analysis. |
| 31 | + |
| 32 | +## Known Issues/Limitations |
| 33 | + |
| 34 | +See https://github.com/johnthagen/clion-cppcheck/issues for a complete list of tracked issues and enhancements requests. |
| 35 | + |
| 36 | +### Analyzing header files |
| 37 | + |
| 38 | +Cppcheck is not designed to be run on header files (`.h`) directly, as must be done for this |
40 | 39 | plugin, and as a result may have false positives.
|
41 | 40 |
|
42 |
| -When run on header files directly, `cppcheck` defaults to C as the language, which will generate |
43 |
| -false positives for C++ projects. C++ projects should append `--language=c++` to the |
44 |
| -`cppcheck` options. |
| 41 | +When run on header files directly, Cppcheck defaults to C as the language, which will generate |
| 42 | +false positives for C++ projects. So `--language=c++` is implicitly added as option when analyzing header files. |
| 43 | + |
| 44 | +It will also provide `unusedFunction` and `unusedStructMember` false positives so these findings are being suppressed. |
| 45 | + |
| 46 | +Related issues:<br/> |
| 47 | +https://github.com/johnthagen/clion-cppcheck/issues/22 |
| 48 | +https://github.com/johnthagen/clion-cppcheck/issues/52 |
| 49 | + |
| 50 | +### Analyzing multiple configurations |
| 51 | + |
| 52 | +By default Cppcheck tries to determine all the available configurations for a file (i.e. all combination of the used |
| 53 | +preprocessor defines). As the plugin doesn't get the current list of defines this may lead to findings shown in code |
| 54 | +which is shown as disabled in the editor. To check just a specific configuration you can either add defines using `-D` |
| 55 | +to the options. Or you can limit the configurations to a single one adding `--max-configs=1`. |
| 56 | + |
| 57 | +By default Limiting the configurations also decreases the time of the analysis. |
| 58 | + |
| 59 | +By default a maximum of 12 configurations is checked. This may lead to some code which might actually be active not to |
| 60 | +show any findings. This can also be controlled by the `--max-configs=<n>` option. |
| 61 | + |
| 62 | +Related issues:<br/> |
| 63 | +https://github.com/johnthagen/clion-cppcheck/issues/34 |
| 64 | +https://github.com/johnthagen/clion-cppcheck/issues/52 |
| 65 | + |
| 66 | +### Multiple include paths |
| 67 | + |
| 68 | +No additional includes path are being passed to Cppcheck for the analysis which might result in false positives or not |
| 69 | +all findings being shown. |
| 70 | + |
| 71 | +You can add additional include path using the `-I <path>` options. |
| 72 | + |
| 73 | +Related issues:<br/> |
| 74 | +https://github.com/johnthagen/clion-cppcheck/issues/52 |
| 75 | +https://github.com/johnthagen/clion-cppcheck/issues/55 |
| 76 | + |
| 77 | +### Batch analysis |
| 78 | + |
| 79 | +The batch analysis passes the files individually to Cppcheck just like the highlighting inspections. So if you pass a |
| 80 | +folder to the batch analysis it might not show the same findings as when passing a folder to `Cppcheck` itself. |
| 81 | + |
| 82 | +It will also pass all the contents of the folder to the analysis and not just project files. This might lead to |
| 83 | +unexpected findings. |
| 84 | + |
| 85 | +Also some findings in headers files triggered by the analysis of a source files are not being shown. |
| 86 | + |
| 87 | +Related issues:<br/> |
| 88 | +https://github.com/johnthagen/clion-cppcheck/issues/54 |
| 89 | + |
| 90 | +### Showing raw output |
| 91 | + |
| 92 | +`Show Cppcheck XML Output` only shows the XML result of the latest analysis. If you need to view the results for a |
| 93 | +specific file make sure it was the last one analyzed. |
| 94 | + |
| 95 | +Related issues:<br/> |
| 96 | +https://github.com/johnthagen/clion-cppcheck/issues/53 |
| 97 | + |
| 98 | +### External libraries / System includes |
| 99 | + |
| 100 | +Cppcheck does not support analyzing of external library or system includes. It provides profiles for several external |
| 101 | +libraries which describe the contents and behavior of the includes which allows it to finding issues with usage of them |
| 102 | +in the code. To add such a profile to your analysis you need to specify it via the `--library=<name>` option. The |
| 103 | +available profile can be found in the `cfg` folder of your `Cppcheck` installation. |
| 104 | + |
| 105 | +### Global options |
| 106 | + |
| 107 | +Currently the configured options are global and not per project. |
| 108 | + |
| 109 | +Related issues:<br/> |
| 110 | +https://github.com/johnthagen/clion-cppcheck/issues/52 |
45 | 111 |
|
46 | 112 | ## Development
|
47 | 113 |
|
@@ -112,7 +178,7 @@ Support Cppcheck >1.89. (Contribution by @SJ-Innovation)
|
112 | 178 |
|
113 | 179 | ### 1.2.0 - 2018-04-11
|
114 | 180 |
|
115 |
| -Greatly improve plugin responsiveness to changes by using virtual files to interact with `cppcheck`. |
| 181 | +Greatly improve plugin responsiveness to changes by using virtual files to interact with Cppcheck. |
116 | 182 | (Contribution by @fastasturtle)
|
117 | 183 |
|
118 | 184 | ### 1.1.0 - 2018-04-02
|
@@ -158,7 +224,7 @@ Fix execution on Linux.
|
158 | 224 |
|
159 | 225 | ### 1.0.1 - 2016-01-11
|
160 | 226 |
|
161 |
| -Fix possible out of bounds line number when ``cppcheck`` gets out of sync with in-memory file. |
| 227 | +Fix possible out of bounds line number when Cppcheck gets out of sync with in-memory file. |
162 | 228 |
|
163 | 229 | ### 1.0.0 - 2016-01-07
|
164 | 230 |
|
|
0 commit comments