From f2acdb5855382b10be9ee93629bbf5c89b70df56 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 28 Mar 2023 12:12:41 +0200 Subject: [PATCH 1/5] README.md: documented `Show Cppcheck XML Output` action and its limitations --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4a831d5..d134690 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ See - [`cppcheck` in JetBrains Plugin Repository][cppcheck_plugin] -## Usage +### Initial Configuration 1. Install the [`cppcheck`](http://cppcheck.sourceforge.net/) tool using the instructions on its homepage. This plugin does **not** bundle the `cppcheck` tool itself, which must be installed separately. @@ -34,6 +34,12 @@ See [cppcheck_plugin]: https://plugins.jetbrains.com/plugin/8143 +## Usage + +### Provided Actions + +The plugin provides the `Show Cppcheck XML Output` action which will show the raw XML output of the latest finished analysis. + ## Known Issues `cppcheck` is not designed to be run on header files (`.h`) directly, as must be done for this @@ -43,6 +49,9 @@ When run on header files directly, `cppcheck` defaults to C as the language, whi false positives for C++ projects. C++ projects should append `--language=c++` to the `cppcheck` options. +`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. + ## Development To run the plugin from source, open this project in IntelliJ and create a new "Plugin" run configuration. Running or From 2fec3b63e9002f5264eca19bc06056763e792dfb Mon Sep 17 00:00:00 2001 From: firewave Date: Sat, 12 Mar 2022 09:55:56 +0100 Subject: [PATCH 2/5] README.md: re-wrote "Known Issues" section --- README.md | 76 +++++++++++++++++++++++++++++++++-- resources/META-INF/plugin.xml | 6 +-- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index d134690..4a1ddeb 100644 --- a/README.md +++ b/README.md @@ -40,18 +40,86 @@ See The plugin provides the `Show Cppcheck XML Output` action which will show the raw XML output of the latest finished analysis. -## Known Issues +## Known Issues/Limitations + +See https://github.com/johnthagen/clion-cppcheck/issues for a complete list of tracked issues and enhancements requests. + +### Analyzing header files `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. C++ projects should append `--language=c++` to the -`cppcheck` options. +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. + +Related issues:
+https://github.com/johnthagen/clion-cppcheck/issues/22 +https://github.com/johnthagen/clion-cppcheck/issues/52 + +### Analyzing multiple configurations + +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=` option. + +Related issues:
+https://github.com/johnthagen/clion-cppcheck/issues/34 +https://github.com/johnthagen/clion-cppcheck/issues/52 + +### Multiple include paths + +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 ` options. + +Related issues:
+https://github.com/johnthagen/clion-cppcheck/issues/52 +https://github.com/johnthagen/clion-cppcheck/issues/55 -`Show Cppcheck XML Output` only shows the XML result of the latest analysis. If you need to view the results for a +### Batch analysis + +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:
+https://github.com/johnthagen/clion-cppcheck/issues/54 + +### Showing raw output + +`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:
+https://github.com/johnthagen/clion-cppcheck/issues/53 + +### External libraries / System includes + +`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=` option. The +available profile can be found in the `cfg` folder of your `cppcheck` installation. + +### Global options + +Currently the configured options are global and not per project. + +Related issues:
+https://github.com/johnthagen/clion-cppcheck/issues/52 + ## Development To run the plugin from source, open this project in IntelliJ and create a new "Plugin" run configuration. Running or diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index ca04f2b..eed6722 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -52,11 +52,7 @@
Known issues:
- 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. C++ projects should leave --language=c++ appended to the - Cppcheck options.
+ Please refer to Known Issues.
]]> Date: Tue, 28 Mar 2023 13:52:41 +0200 Subject: [PATCH 3/5] some minor documentation improvements --- README.md | 20 ++++++++++++-------- resources/META-INF/plugin.xml | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4a1ddeb..9abff33 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,24 @@ -# CLion-cppcheck +# clion-cppcheck -- Runs `cppcheck` on the fly while you write code. -- Highlights lines and displays `cppcheck` error messages. -- Supports passing options to `cppcheck`. +A plugin for JetBrains IDEs to provide inspections for C/C++ files utilizing the static analyzer [Cppcheck](https://cppcheck.sourceforge.io/). This project is supported with a free open source license of CLion from [JetBrains](https://www.jetbrains.com/?from=clion-cppcheck). +## Features + +- Runs `Cppcheck` on the fly while you write code. +- Highlights lines and displays `Cppcheck` error messages. +- Supports passing options to `Cppcheck`. + ## Installation -See -[Installing, Updating and Uninstalling Repository Plugins](https://www.jetbrains.com/help/clion/managing-plugins.html) +Install the [`cppcheck` plugin][cppcheck_plugin] from the JetBrains Marketplace. -- [`cppcheck` in JetBrains Plugin Repository][cppcheck_plugin] +See +[Installing, Updating and Uninstalling Repository Plugins](https://www.jetbrains.com/help/clion/managing-plugins.html) for more details. -### Initial Configuration +### Initial Plugin Configuration 1. Install the [`cppcheck`](http://cppcheck.sourceforge.net/) tool using the instructions on its homepage. This plugin does **not** bundle the `cppcheck` tool itself, which must be installed separately. diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index eed6722..25b7645 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -5,7 +5,7 @@ johnthagen
+ A plugin for JetBrains IDEs to provide inspections for C/C++ files utilizing the static analyzer Cppcheck.

Features:
    From 2474b68fe5f1d99759416f1f21052811ffac8ef4 Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 28 Mar 2023 13:54:24 +0200 Subject: [PATCH 4/5] README.md: use proper capitalization for `Cppcheck` and do not quote it --- README.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9abff33..3725bee 100644 --- a/README.md +++ b/README.md @@ -21,19 +21,19 @@ See ### Initial Plugin Configuration 1. Install the [`cppcheck`](http://cppcheck.sourceforge.net/) tool using the instructions on its homepage. This plugin - does **not** bundle the `cppcheck` tool itself, which must be installed separately. + does **not** bundle the Cppcheck tool itself, which must be installed separately. 2. Install the [cppcheck plugin][cppcheck_plugin] into CLion. -3. Configure the plugin with the **absolute** path to the `cppcheck` executable into the `cppcheck path` option. +3. Configure the plugin with the **absolute** path to the Cppcheck executable into the `cppcheck path` option. 1. Windows 1. File | Settings | Cppcheck configuration 2. Usually the path is `C:\Program Files (x86)\Cppcheck\cppcheck.exe` 2. macOS: 1. CLion | Preferences | Cppcheck configuration - 2. In a terminal run `which cppcheck` to find the path to `cppcheck`. If you installed it with + 2. In a terminal run `which cppcheck` to find the path to Cppcheck. If you installed it with [Homebrew](https://brew.sh/), the path will be `/usr/local/bin/cppcheck`. 3. Linux 1. File | Settings | Cppcheck configuration - 2. In a terminal run `which cppcheck` to find the path to `cppcheck`. If you installed it with your + 2. In a terminal run `which cppcheck` to find the path to Cppcheck. If you installed it with your system's package manager, it is probably located at `/usr/bin/cppcheck`. [cppcheck_plugin]: https://plugins.jetbrains.com/plugin/8143 @@ -50,10 +50,10 @@ See https://github.com/johnthagen/clion-cppcheck/issues for a complete list of t ### Analyzing header files -`cppcheck` is not designed to be run on header files (`.h`) directly, as must be done for this +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 +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. @@ -64,7 +64,7 @@ https://github.com/johnthagen/clion-cppcheck/issues/52 ### Analyzing multiple configurations -By default `cppcheck` tries to determine all the available configurations for a file (i.e. all combination of the used +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`. @@ -80,7 +80,7 @@ https://github.com/johnthagen/clion-cppcheck/issues/52 ### Multiple include paths -No additional includes path are being passed to `cppcheck` for the analysis which might result in false positives or not +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 ` options. @@ -91,8 +91,8 @@ https://github.com/johnthagen/clion-cppcheck/issues/55 ### Batch analysis -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. +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. @@ -112,10 +112,10 @@ https://github.com/johnthagen/clion-cppcheck/issues/53 ### External libraries / System includes -`cppcheck` does not support analyzing of external library or system includes. It provides profiles for several external +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=` option. The -available profile can be found in the `cfg` folder of your `cppcheck` installation. +available profile can be found in the `cfg` folder of your `Cppcheck` installation. ### Global options @@ -192,7 +192,7 @@ Support Cppcheck >1.89. (Contribution by @SJ-Innovation) ### 1.2.0 - 2018-04-11 -Greatly improve plugin responsiveness to changes by using virtual files to interact with `cppcheck`. +Greatly improve plugin responsiveness to changes by using virtual files to interact with Cppcheck. (Contribution by @fastasturtle) ### 1.1.0 - 2018-04-02 @@ -238,7 +238,7 @@ Fix execution on Linux. ### 1.0.1 - 2016-01-11 -Fix possible out of bounds line number when ``cppcheck`` gets out of sync with in-memory file. +Fix possible out of bounds line number when Cppcheck gets out of sync with in-memory file. ### 1.0.0 - 2016-01-07 From 5075a9b873c00d66c875ec474aafea0daeecd1ac Mon Sep 17 00:00:00 2001 From: firewave Date: Tue, 28 Mar 2023 13:51:33 +0200 Subject: [PATCH 5/5] README.md: rewrote `Installation` section - refs #58 --- README.md | 29 +++++++---------------------- resources/META-INF/plugin.xml | 35 +---------------------------------- 2 files changed, 8 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index 3725bee..2479817 100644 --- a/README.md +++ b/README.md @@ -13,30 +13,15 @@ This project is supported with a free open source license of CLion from ## Installation -Install the [`cppcheck` plugin][cppcheck_plugin] from the JetBrains Marketplace. - -See +- Install the `cppcheck` plugin from the JetBrains Marketplace: https://plugins.jetbrains.com/plugin/8143-cppcheck. See [Installing, Updating and Uninstalling Repository Plugins](https://www.jetbrains.com/help/clion/managing-plugins.html) for more details. -### Initial Plugin Configuration - -1. Install the [`cppcheck`](http://cppcheck.sourceforge.net/) tool using the instructions on its homepage. This plugin - does **not** bundle the Cppcheck tool itself, which must be installed separately. -2. Install the [cppcheck plugin][cppcheck_plugin] into CLion. -3. Configure the plugin with the **absolute** path to the Cppcheck executable into the `cppcheck path` option. - 1. Windows - 1. File | Settings | Cppcheck configuration - 2. Usually the path is `C:\Program Files (x86)\Cppcheck\cppcheck.exe` - 2. macOS: - 1. CLion | Preferences | Cppcheck configuration - 2. In a terminal run `which cppcheck` to find the path to Cppcheck. If you installed it with - [Homebrew](https://brew.sh/), the path will be `/usr/local/bin/cppcheck`. - 3. Linux - 1. File | Settings | Cppcheck configuration - 2. In a terminal run `which cppcheck` to find the path to Cppcheck. If you installed it with your - system's package manager, it is probably located at `/usr/bin/cppcheck`. - -[cppcheck_plugin]: https://plugins.jetbrains.com/plugin/8143 +- 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 the `Cppcheck 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` 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`. ## Usage diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 25b7645..9097f6f 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -16,40 +16,7 @@
    Usage:
    -
      -
    • - Install the cppcheck tool using directions on its homepage. - This plugin does not bundle the Cppcheck tool itself, which must be installed separately. -
    • -
    • Install this Cppcheck plugin into CLion
    • -
    • Configure the plugin with the absolute path to the Cppcheck executable into the - 'Cppcheck Path' configuration field
    • -
        -
      • Windows -
          -
        • File | Settings | Cppcheck Configuration
        • -
        • Usually the path is C:\Program Files (x86)\Cppcheck\cppcheck.exe
        • -
        -
      • -
      • macOS -
          -
        • CLion | Preferences | Cppcheck Configuration
        • -
        • In a terminal run `which cppcheck` to find the path to Cppcheck. - If you installed it with Homebrew, the path will be - /usr/local/bin/cppcheck
        • -
        -
      • -
      • Linux -
          -
        • File | Settings | Cppcheck Configuration
        • -
        • In a terminal run `which cppcheck` to find the path to Cppcheck. - If you installed it with your system's package manager, it is probably located at - /usr/bin/cppcheck
        • -
        -
      • - -
      -
      + Please refer to Installation.
      Known issues:
      Please refer to Known Issues.