Skip to content

Commit 53d68b7

Browse files
committed
show some Cppcheck messages on file-level / use full file path in balloon
1 parent 77d081f commit 53d68b7

File tree

3 files changed

+60
-33
lines changed

3 files changed

+60
-33
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Deployment.
6363
- Use unique file names for temporary files used for analysis. (Contribution by @firewave)
6464
- Properly handle `debug` messages generated by `--debug-warnings`. (Contribution by @firewave)
6565
- Added `.cl`, `.hxx`, `.tpp` and `.txx` to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave)
66+
- Show some Cppcheck messages (`toomanyconfigs`, `missingInclude`, `noValidConfiguration`) on file-level. (Contribution by @firewave)
6667

6768
### 1.5.1 - 2020-11-12
6869

resources/META-INF/plugin.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@
6565
- Fixed scanning of files with whitespaces in name. (Contribution by @firewave)
6666
- Only scan files which actually exist. (Contribution by @firewave)
6767
- Use unique file names for temporary files used for analysis. (Contribution by @firewave)
68-
- Properly handle "debug" messages generated by --debug-warnings. (Contribution by @firewave
69-
- Added .cl, .hxx, .tpp and .txx to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave
68+
- Properly handle "debug" messages generated by --debug-warnings. (Contribution by @firewave)
69+
- Added .cl, .hxx, .tpp and .txx to list of supported file extensions - now matches the ones supported by Cppcheck internally. (Contribution by @firewave)
70+
- Show some Cppcheck messages (toomanyconfigs, missingInclude, noValidConfiguration) on file-level. (Contribution by @firewave)
7071
]]>
7172
</change-notes>
7273

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

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
7070
if (VERBOSE_LOG) {
7171
// TODO: provide XML output via a "Show Cppcheck output" action - event log messages are truncated
7272
Notifications.Bus.notify(new Notification("Cppcheck",
73-
"Cppcheck execution output for " + psiFile.getName(),
73+
"Cppcheck execution output for " + psiFile.getVirtualFile().getCanonicalPath(),
7474
cppcheckOutput,
7575
NotificationType.INFORMATION));
7676
}
@@ -96,16 +96,6 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
9696

9797
final String id = attributes.getNamedItem("id").getNodeValue();
9898

99-
// Skip the "toomanyconfigs" error
100-
/*
101-
<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">
102-
<location file="C:\Users\Name\AppData\Local\Temp\___valueflow.cpp" line="0" column="0"/>
103-
</error>
104-
*/
105-
if (id.equals("toomanyconfigs")) {
106-
continue;
107-
}
108-
10999
// Skip the "missingIncludeSystem" error
110100
/*
111101
<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."/>
@@ -131,41 +121,76 @@ public static List<ProblemDescriptor> parseOutput(@NotNull final PsiFile psiFile
131121
}
132122
}
133123

124+
int lineNumber = 0;
125+
int column = 0;
126+
127+
/*
128+
<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."/>
129+
*/
130+
// TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis
131+
if (id.equals("missingInclude")) {
132+
// is a global warning without location information
133+
}
134134
// ignore entries without location e.g. missingIncludeSystem
135-
if (location == null) {
135+
else if (location == null) {
136136
continue;
137137
}
138+
else {
139+
final NamedNodeMap locationAttributes = location.getAttributes();
140+
final String fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName();
141+
lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue());
142+
column = Integer.parseInt(locationAttributes.getNamedItem("column").getNodeValue()); // TODO
143+
144+
// If a file #include's header files, Cppcheck will also run on the header files and print
145+
// any errors. These errors don't apply to the current file and should not be drawn. They can
146+
// be distinguished by checking the file name.
147+
if (!fileName.equals(sourceFileName)) {
148+
continue;
149+
}
150+
}
138151

139-
final NamedNodeMap locationAttributes = location.getAttributes();
140-
final String fileName = new File(locationAttributes.getNamedItem("file").getNodeValue()).getName();
141-
int lineNumber = Integer.parseInt(locationAttributes.getNamedItem("line").getNodeValue());
142-
final int column = Integer.parseInt(locationAttributes.getNamedItem("column").getNodeValue()); // TODO
152+
// leaving it at null will report it for the whole file
153+
TextRange range = null;
143154

144-
// If a file #include's header files, Cppcheck will also run on the header files and print
145-
// any errors. These errors don't apply to the current file and should not be drawn. They can
146-
// be distinguished by checking the file name.
147-
if (!fileName.equals(sourceFileName)) {
148-
continue;
155+
/*
156+
<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">
157+
<location file="C:\Users\Name\AppData\Local\Temp\___valueflow.cpp" line="0" column="0"/>
158+
</error>
159+
*/
160+
if (id.equals("toomanyconfigs")) {
161+
// show as message for the file
149162
}
150-
151-
// Cppcheck error
152-
if (lineNumber <= 0 || lineNumber > document.getLineCount()) {
163+
// TODO: handle like any warning when Cppcheck provides the --check-config results with the normal analysis
164+
else if (id.equals("missingInclude")) {
165+
// show as message for the file
166+
}
167+
/*
168+
<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;">
169+
<location file="/mnt/s/GitHub/cppcheck-fw/gui/temp/moc_platforms.cpp" line="0" column="0"/>
170+
</error>
171+
*/
172+
else if (id.equals("noValidConfiguration")) {
173+
// show as message for the file
174+
}
175+
else if (lineNumber <= 0 || lineNumber > document.getLineCount()) {
153176
Notifications.Bus.notify(new Notification("Cppcheck",
154177
"Cppcheck line number out-of-bounds " + i,
155-
id + " " + severity + " " + inconclusive + " " + errorMessage + " " + fileName + " " + lineNumber + " " + column,
178+
id + " " + severity + " " + inconclusive + " " + errorMessage + " " + psiFile.getVirtualFile().getCanonicalPath() + " " + lineNumber + " " + column,
156179
NotificationType.ERROR));
157180
continue;
158181
}
182+
else {
183+
// Document counts lines starting at 0, rather than 1 like in cppcheck.
184+
lineNumber -= 1;
159185

160-
// Document counts lines starting at 0, rather than 1 like in cppcheck.
161-
lineNumber -= 1;
162-
163-
final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
164-
final int lineEndOffset = document.getLineEndOffset(lineNumber);
186+
final int lineStartOffset = DocumentUtil.getFirstNonSpaceCharOffset(document, lineNumber);
187+
final int lineEndOffset = document.getLineEndOffset(lineNumber);
188+
range = TextRange.create(lineStartOffset, lineEndOffset);
189+
}
165190

166191
final ProblemDescriptor problemDescriptor = manager.createProblemDescriptor(
167192
psiFile,
168-
TextRange.create(lineStartOffset, lineEndOffset),
193+
range,
169194
"Cppcheck: (" + severity + (inconclusive ? INCONCLUSIVE_TEXT : "") + ") " + id + ": " + errorMessage,
170195
severityToHighlightType(severity),
171196
true);

0 commit comments

Comments
 (0)