Skip to content

Commit 53ed78d

Browse files
committed
show some Cppcheck messages on file-level
1 parent 21967b7 commit 53ed78d

File tree

3 files changed

+62
-29
lines changed

3 files changed

+62
-29
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Deployment.
7070
- Added `.cl`, `.hxx`, `.tpp` and `.txx` to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave)
7171
- Internally suppress `unusedFunction` and `unusedStructMember` (for header files only) warnings to avoid false positives. (Contribution by @firewave)
7272
- Fixed `information` messages not being shown at all. (Contribution by @firewave)
73+
- Show some Cppcheck messages (`toomanyconfigs`, `missingInclude`, `noValidConfiguration`) on file-level. (Contribution by @firewave)
7374

7475
### 1.5.1 - 2020-11-12
7576

resources/META-INF/plugin.xml

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
- Added .cl, .hxx, .tpp and .txx to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave)
6969
- Internally suppress "unusedFunction" and "unusedStructMember" (for header files only) warnings to avoid false positives. (Contribution by @firewave)
7070
- Fixed "information" messages not being shown at all. (Contribution by @firewave)
71+
- Show some Cppcheck messages (toomanyconfigs, missingInclude, noValidConfiguration) on file-level. (Contribution by @firewave)
7172
]]>
7273
</change-notes>
7374

src/com/github/johnthagen/cppcheck/CppCheckInspectionImpl.java

+60-29
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,6 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
9393

9494
final String id = attributes.getNamedItem("id").getNodeValue();
9595

96-
// Skip the "toomanyconfigs" error
97-
/*
98-
<error id="toomanyconfigs" severity="information" msg="Too many #ifdef configurations - cppcheck only checks 1 of 12 configurations. Use --force to check all configurations." verbose="The checking of the file will be interrupted because there are too many #ifdef configurations. Checking of all #ifdef configurations can be forced by --force command line option or from GUI preferences. However that may increase the checking time." cwe="398">
99-
<location file="C:\Users\Name\AppData\Local\Temp\___valueflow.cpp" line="0" column="0"/>
100-
</error>
101-
*/
102-
if (id.equals("toomanyconfigs")) {
103-
continue;
104-
}
105-
10696
// Skip the "missingIncludeSystem" error
10797
/*
10898
<error id="missingIncludeSystem" severity="information" msg="Cppcheck cannot find all the include files (use --check-config for details)" verbose="Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project&apos;s include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config."/>
@@ -148,43 +138,84 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
148138
}
149139
}
150140

141+
String fileName = null;
142+
int lineNumber = 0;
143+
int column = 0;
144+
145+
/*
146+
<error id="missingInclude" severity="information" msg="Cppcheck cannot find all the include files (use --check-config for details)" verbose="Cppcheck cannot find all the include files. Cppcheck can check the code without the include files found. But the results will probably be more accurate if all the include files are found. Please check your project&apos;s include directories and add all of them as include directories for Cppcheck. To see what files Cppcheck cannot find use --check-config."/>
147+
*/
148+
// TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis
149+
if (id.equals("missingInclude")) {
150+
// is a global warning without location information
151+
}
151152
// ignore entries without location e.g. missingIncludeSystem
152-
if (location == null) {
153+
else if (location == null) {
153154
CppcheckNotification.send("no location for " + psiFile.getVirtualFile().getCanonicalPath(),
154155
id + " " + severity + " " + inconclusive + " " + errorMessage,
155156
NotificationType.ERROR);
156157
continue;
157158
}
159+
else {
160+
final NamedNodeMap locationAttributes = location.getAttributes();
161+
fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName();
162+
lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue());
163+
column = Integer.parseInt(locationAttributes.getNamedItem("column").getNodeValue()); // TODO: use in problem?
164+
165+
// If a file #include's header files, Cppcheck will also run on the header files and print
166+
// any errors. These errors don't apply to the current file and should not be drawn. They can
167+
// be distinguished by checking the file name.
168+
if (!fileName.equals(sourceFileName)) {
169+
continue;
170+
}
171+
}
158172

159-
final NamedNodeMap locationAttributes = location.getAttributes();
160-
final String fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName();
161-
int lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue());
162-
final int column = Integer.parseInt(locationAttributes.getNamedItem("column").getNodeValue()); // TODO
173+
// leaving it at null will report it for the whole file
174+
TextRange range = null;
163175

164-
// If a file #include's header files, Cppcheck will also run on the header files and print
165-
// any errors. These errors don't apply to the current file and should not be drawn. They can
166-
// be distinguished by checking the file name.
167-
if (!fileName.equals(sourceFileName)) {
168-
continue;
176+
/*
177+
<error id="toomanyconfigs" severity="information" msg="Too many #ifdef configurations - cppcheck only checks 1 of 12 configurations. Use --force to check all configurations." verbose="The checking of the file will be interrupted because there are too many #ifdef configurations. Checking of all #ifdef configurations can be forced by --force command line option or from GUI preferences. However that may increase the checking time." cwe="398">
178+
<location file="C:\Users\Name\AppData\Local\Temp\___valueflow.cpp" line="0" column="0"/>
179+
</error>
180+
*/
181+
if (id.equals("toomanyconfigs")) {
182+
// show as message for the file
169183
}
170-
171-
// Cppcheck error
172-
if (lineNumber <= 0 || lineNumber > document.getLineCount()) {
184+
// TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis
185+
else if (id.equals("missingInclude")) {
186+
// show as message for the file
187+
}
188+
/*
189+
<error id="noValidConfiguration" severity="information" msg="This file is not analyzed. Cppcheck failed to extract a valid configuration. Use -v for more details." verbose="This file is not analyzed. Cppcheck failed to extract a valid configuration. The tested configurations have these preprocessor errors:\012&apos;&apos; : [/mnt/s/GitHub/cppcheck-fw/gui/temp/moc_platforms.cpp:13] #error &quot;The header file &apos;platforms.h&apos; doesn&apos;t include &lt;QObject&gt;.&quot;\012Q_MOC_OUTPUT_REVISION : [/mnt/s/GitHub/cppcheck-fw/gui/temp/moc_platforms.cpp:15] #error &quot;This file was generated using the moc from 5.12.5. It&quot;">
190+
<location file="/mnt/s/GitHub/cppcheck-fw/gui/temp/moc_platforms.cpp" line="0" column="0"/>
191+
</error>
192+
*/
193+
else if (id.equals("noValidConfiguration")) {
194+
// show as message for the file
195+
// show the verbose message as notification since it contains important details
196+
final String verboseMessage = attributes.getNamedItem("verbose").getNodeValue();
197+
CppcheckNotification.send("noValidConfiguration for "+ psiFile.getVirtualFile().getCanonicalPath(),
198+
verboseMessage,
199+
NotificationType.INFORMATION);
200+
}
201+
else if (lineNumber <= 0 || lineNumber > document.getLineCount()) {
173202
CppcheckNotification.send("line number out-of-bounds for " + psiFile.getVirtualFile().getCanonicalPath(),
174203
id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column,
175204
NotificationType.ERROR);
176205
continue;
177206
}
207+
else {
208+
// Document counts lines starting at 0, rather than 1 like in cppcheck.
209+
lineNumber -= 1;
178210

179-
// Document counts lines starting at 0, rather than 1 like in cppcheck.
180-
lineNumber -= 1;
181-
182-
final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
183-
final int lineEndOffset = document.getLineEndOffset(lineNumber);
211+
final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
212+
final int lineEndOffset = document.getLineEndOffset(lineNumber);
213+
range = TextRange.create(lineStartOffset, lineEndOffset);
214+
}
184215

185216
final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
186217
psiFile,
187-
TextRange.create(lineStartOffset, lineEndOffset),
218+
range,
188219
"Cppcheck: (" + severity + (inconclusive ? INCONCLUSIVE_TEXT : "") + ") " + id + ": " + errorMessage,
189220
severityToHighlightType(severity),
190221
true);

0 commit comments

Comments
 (0)