Skip to content

Commit 68c52dd

Browse files
committed
Refactoring information messages.
Currently the information severity messages are outputted as error messages with Severity::Information. This causes constant confusion as people think it as mildest error severity (and rightfully so). When it was meant to be for printing messages about the checking procedure itself (like missing header files etc). So I'm adding a new function for the ErrorLogger for printing these informative messages. This makes clear the distinction of errors found from the code and messages related to the checking itself. It also makes it easier for clients to handle these separately.
1 parent 14591b3 commit 68c52dd

8 files changed

Lines changed: 41 additions & 6 deletions

File tree

cli/cppcheckexecutor.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ int CppCheckExecutor::check(int argc, const char* const argv[])
207207
"--check-config.",
208208
"missingInclude",
209209
false);
210-
reportErr(msg);
210+
reportInfo(msg);
211211
}
212212
}
213213

@@ -265,6 +265,11 @@ void CppCheckExecutor::reportProgress(const std::string &filename, const char st
265265
}
266266
}
267267

268+
void CppCheckExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
269+
{
270+
reportOut(msg.toXML(false, _settings._xml_version));
271+
}
272+
268273
void CppCheckExecutor::reportStatus(size_t fileindex, size_t filecount, size_t sizedone, size_t sizetotal)
269274
{
270275
if (filecount > 1) {

cli/cppcheckexecutor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ class CppCheckExecutor : public ErrorLogger {
7272

7373
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
7474

75+
/**
76+
* Output information messages.
77+
*/
78+
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg);
79+
7580
/**
7681
* Information about how many files have been checked
7782
*

cli/threadexecutor.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &msg)
290290
writeToPipe(REPORT_ERROR, msg.serialize());
291291
}
292292

293+
void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
294+
{
295+
writeToPipe(REPORT_OUT, msg.serialize());
296+
}
297+
293298
#else
294299

295300
void ThreadExecutor::addFileContent(const std::string &/*path*/, const std::string &/*content*/)
@@ -311,4 +316,9 @@ void ThreadExecutor::reportErr(const ErrorLogger::ErrorMessage &/*msg*/)
311316

312317
}
313318

319+
void ThreadExecutor::reportInfo(const ErrorLogger::ErrorMessage &msg)
320+
{
321+
322+
}
323+
314324
#endif

cli/threadexecutor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class ThreadExecutor : public ErrorLogger {
4444
unsigned int check();
4545
virtual void reportOut(const std::string &outmsg);
4646
virtual void reportErr(const ErrorLogger::ErrorMessage &msg);
47+
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg);
4748

4849
/**
4950
* @brief Add content to a file, to be used in unit testing.

lib/cppcheck.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,7 @@ unsigned int CppCheck::processFile(const std::string& filename)
209209
"toomanyconfigs",
210210
false);
211211

212-
reportErr(errmsg);
213-
212+
reportInfo(errmsg);
214213
break;
215214
}
216215

@@ -512,6 +511,11 @@ void CppCheck::reportProgress(const std::string &filename, const char stage[], c
512511
_errorLogger.reportProgress(filename, stage, value);
513512
}
514513

514+
void CppCheck::reportInfo(const ErrorLogger::ErrorMessage &msg)
515+
{
516+
_errorLogger.reportInfo(msg);
517+
}
518+
515519
void CppCheck::reportStatus(unsigned int /*fileindex*/, unsigned int /*filecount*/, size_t /*sizedone*/, size_t /*sizetotal*/)
516520
{
517521

lib/cppcheck.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,11 @@ class CPPCHECKLIB CppCheck : ErrorLogger {
175175

176176
void reportProgress(const std::string &filename, const char stage[], const unsigned int value);
177177

178+
/**
179+
* Output information messages.
180+
*/
181+
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg);
182+
178183
CheckUnusedFunctions _checkUnusedFunctions;
179184
ErrorLogger &_errorLogger;
180185

lib/errorlogger.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,7 @@ class CPPCHECKLIB ErrorLogger {
266266
* Information about found errors and warnings is directed
267267
* here. Override this to receive the errormessages.
268268
*
269-
* @param msg Location and other information about the found.
270-
* error
269+
* @param msg Location and other information about the found error.
271270
*/
272271
virtual void reportErr(const ErrorLogger::ErrorMessage &msg) = 0;
273272

@@ -283,6 +282,12 @@ class CPPCHECKLIB ErrorLogger {
283282
(void)value;
284283
}
285284

285+
/**
286+
* Output information messages.
287+
* @param msg Location and other information about the found error.
288+
*/
289+
virtual void reportInfo(const ErrorLogger::ErrorMessage &msg) = 0;
290+
286291
/**
287292
* Report list of unmatched suppressions
288293
* @param unmatched list of unmatched suppressions (from Settings::Suppressions::getUnmatched(Local|Global)Suppressions)

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2100,7 +2100,7 @@ void Preprocessor::missingInclude(const std::string &filename, unsigned int line
21002100
const std::string id = userheader ? "missingInclude" : "debug";
21012101
ErrorLogger::ErrorMessage errmsg(locationList, severity, "Include file: \"" + header + "\" not found.", id, false);
21022102
errmsg.file0 = file0;
2103-
_errorLogger->reportErr(errmsg);
2103+
errorLogger->reportInfo(errmsg);
21042104
}
21052105

21062106
/**

0 commit comments

Comments
 (0)