diff --git a/README.md b/README.md index 3d94664..e33dca0 100644 --- a/README.md +++ b/README.md @@ -36,12 +36,59 @@ See ## Known Issues +### 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. + +### 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. + +### 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. + +### 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. + +### Showing raw output + +Currently there is no way to view the raw output of the `cppcheck` execution. + +### 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. ## Development @@ -60,6 +107,9 @@ Deployment. ## Releases +### 1.7.0 - XXXX-XX-XX +- Show some Cppcheck messages (`toomanyconfigs`, `missingInclude`, `noValidConfiguration`) on file-level. See [Known Issues](#known-issues) on how to fix these. (Contribution by @firewave) + ### 1.6.2 - 2022-01-25 - Fixed `NullPointerException` with Cppcheck < 1.89 caused by missing `column` attribute in XML result. diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 7f940d8..cccc55c 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -1,7 +1,7 @@ com.github.johnthagen.cppcheck cppcheck - 1.6.2 + 1.7.0 johnthagen 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.
]]>
Known Issues on how to fix these. (Contribution by @firewave) ]]> diff --git a/src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java b/src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java index edbb0c8..83be06e 100644 --- a/src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java +++ b/src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java @@ -93,16 +93,6 @@ public static List parseOutput(@NotNull final PsiFile psiFile final String id = attributes.getNamedItem("id").getNodeValue(); - // Skip the "toomanyconfigs" error - /* - - - - */ - if (id.equals("toomanyconfigs")) { - continue; - } - // Skip the "missingIncludeSystem" error /* @@ -116,11 +106,6 @@ public static List parseOutput(@NotNull final PsiFile psiFile continue; } - // suppress this warnings for now - will be properly handled in an upcoming patch - if (id.equals("noValidConfiguration") || id.equals("missingInclude")) { - continue; - } - // we are never interested in these if (id.equals("unmatchedSuppression") || id.equals("purgedConfiguration")) { continue; @@ -148,49 +133,90 @@ public static List parseOutput(@NotNull final PsiFile psiFile } } + String fileName = null; + int lineNumber = 0; + int column = 0; + + /* + + */ + // TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis + if (id.equals("missingInclude")) { + // is a global warning without location information + } // ignore entries without location e.g. missingIncludeSystem - if (location == null) { + else if (location == null) { CppcheckNotification.send("no location for " + psiFile.getVirtualFile().getCanonicalPath(), id + " " + severity + " " + inconclusive + " " + errorMessage, NotificationType.ERROR); continue; } + else { + final NamedNodeMap locationAttributes = location.getAttributes(); + fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName(); + lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue()); + final Node columnAttr = locationAttributes.getNamedItem("column"); + // TODO: use in ProblemDescriptor + column = -1; + // the "column" attribute was added in Cppcheck 1.89 + if (columnAttr != null) { + column = Integer.parseInt(columnAttr.getNodeValue()); + } - final NamedNodeMap locationAttributes = location.getAttributes(); - final String fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName(); - int lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue()); - final Node columnAttr = locationAttributes.getNamedItem("column"); - // TODO: use in ProblemDescriptor - int column = -1; - // the "column" attribute was added in Cppcheck 1.89 - if (columnAttr != null) { - column = Integer.parseInt(columnAttr.getNodeValue()); + // If a file #include's header files, Cppcheck will also run on the header files and print + // any errors. These errors don't apply to the current file and should not be drawn. They can + // be distinguished by checking the file name. + if (!fileName.equals(sourceFileName)) { + continue; + } } - // If a file #include's header files, Cppcheck will also run on the header files and print - // any errors. These errors don't apply to the current file and should not be drawn. They can - // be distinguished by checking the file name. - if (!fileName.equals(sourceFileName)) { - continue; - } + // leaving it at null will report it for the whole file + TextRange range = null; - // Cppcheck error - if (lineNumber <= 0 || lineNumber > document.getLineCount()) { + /* + + + + */ + if (id.equals("toomanyconfigs")) { + // show as message for the file + } + // TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis + else if (id.equals("missingInclude")) { + // show as message for the file + } + /* + + + + */ + else if (id.equals("noValidConfiguration")) { + // show as message for the file + // show the verbose message as notification since it contains important details + final String verboseMessage = attributes.getNamedItem("verbose").getNodeValue(); + CppcheckNotification.send("noValidConfiguration for "+ psiFile.getVirtualFile().getCanonicalPath(), + verboseMessage, + NotificationType.INFORMATION); + } + else if (lineNumber <= 0 || lineNumber > document.getLineCount()) { CppcheckNotification.send("line number out-of-bounds for " + psiFile.getVirtualFile().getCanonicalPath(), id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column, NotificationType.ERROR); continue; } + else { + // Document counts lines starting at 0, rather than 1 like in cppcheck. + lineNumber -= 1; - // Document counts lines starting at 0, rather than 1 like in cppcheck. - lineNumber -= 1; - - final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber); - final int lineEndOffset = document.getLineEndOffset(lineNumber); + final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber); + final int lineEndOffset = document.getLineEndOffset(lineNumber); + range = TextRange.create(lineStartOffset, lineEndOffset); + } final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor( psiFile, - TextRange.create(lineStartOffset, lineEndOffset), + range, "Cppcheck: (" + severity + (inconclusive ? INCONCLUSIVE_TEXT : "") + ") " + id + ": " + errorMessage, severityToHighlightType(severity), true);