Skip to content

Commit

Permalink
Fixed #12281 (IDE plugin integration is broken by checkers report)
Browse files Browse the repository at this point in the history
  • Loading branch information
danmar committed Dec 18, 2023
1 parent 34fb24d commit b1de336
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 23 deletions.
47 changes: 28 additions & 19 deletions cli/cppcheckexecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class CppCheckExecutor::StdLogger : public ErrorLogger
/**
* @brief Write the checkers report
*/
void writeCheckersReport() const;
void writeCheckersReport();

private:
/**
Expand Down Expand Up @@ -281,39 +281,48 @@ int CppCheckExecutor::check_internal(CppCheck& cppcheck) const
cppcheck.tooManyConfigsError(emptyString,0U);
}

if (false && settings.severity.isEnabled(Severity::information)) // <- TODO: settings.safety
mStdLogger->writeCheckersReport();

if (settings.xml) {
mStdLogger->reportErr(ErrorMessage::getXMLFooter());
}

mStdLogger->writeCheckersReport();

if (returnValue)
return settings.exitCode;
return 0;
}

void CppCheckExecutor::StdLogger::writeCheckersReport() const
void CppCheckExecutor::StdLogger::writeCheckersReport()
{
CheckersReport checkersReport(mSettings, mActiveCheckers);
for (const Suppressions::Suppression& s : mSettings.nomsg.getSuppressions()) {
if (s.errorId == "checkersReport")
return;
}

if (!mSettings.quiet) {
const int activeCheckers = checkersReport.getActiveCheckersCount();
const int totalCheckers = checkersReport.getAllCheckersCount();
ErrorMessage msg;
msg.severity = Severity::information;
msg.id = "checkersReport";

const std::string extra = mSettings.verbose ? " (use --checkers-report=<filename> to see details)" : "";
if (mCriticalErrors.empty())
std::cout << "Active checkers: " << activeCheckers << "/" << totalCheckers << extra << std::endl;
else
std::cout << "Active checkers: There was critical errors" << extra << std::endl;
}
CheckersReport checkersReport(mSettings, mActiveCheckers);

if (mSettings.checkersReportFilename.empty())
return;
const int activeCheckers = checkersReport.getActiveCheckersCount();
const int totalCheckers = checkersReport.getAllCheckersCount();

std::ofstream fout(mSettings.checkersReportFilename);
if (fout.is_open())
fout << checkersReport.getReport(mCriticalErrors);
std::string what;
if (mCriticalErrors.empty())
what = std::to_string(activeCheckers) + "/" + std::to_string(totalCheckers);
else
what = "There was critical errors";
msg.setmsg("Active checkers: " + what + " (use --checkers-report=<filename> to see details)");

reportErr(msg);

if (!mSettings.checkersReportFilename.empty()) {
std::ofstream fout(mSettings.checkersReportFilename);
if (fout.is_open())
fout << checkersReport.getReport(mCriticalErrors);
}
}

#ifdef _WIN32
Expand Down
11 changes: 9 additions & 2 deletions lib/suppressions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@

#include "xml.h"

static const char ID_UNUSEDFUNCTION[] = "unusedFunction";
static const char ID_CHECKERSREPORT[] = "checkersReport";

Suppressions::ErrorMessage Suppressions::ErrorMessage::fromErrorMessage(const ::ErrorMessage &msg, const std::set<std::string> &macroNames)
{
Suppressions::ErrorMessage ret;
Expand Down Expand Up @@ -455,7 +458,9 @@ std::list<Suppressions::Suppression> Suppressions::getUnmatchedLocalSuppressions
continue;
if (s.hash > 0)
continue;
if (!unusedFunctionChecking && s.errorId == "unusedFunction")
if (s.errorId == ID_CHECKERSREPORT)
continue;
if (!unusedFunctionChecking && s.errorId == ID_UNUSEDFUNCTION)
continue;
if (tmpFile.empty() || !s.isLocal() || s.fileName != tmpFile)
continue;
Expand All @@ -472,7 +477,9 @@ std::list<Suppressions::Suppression> Suppressions::getUnmatchedGlobalSuppression
continue;
if (s.hash > 0)
continue;
if (!unusedFunctionChecking && s.errorId == "unusedFunction")
if (!unusedFunctionChecking && s.errorId == ID_UNUSEDFUNCTION)
continue;
if (s.errorId == ID_CHECKERSREPORT)
continue;
if (s.isLocal())
continue;
Expand Down
2 changes: 0 additions & 2 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def cppcheck(args, env=None):
comm = p.communicate()
stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
if stdout.find('\nActive checkers:') > 0:
stdout = stdout[:1 + stdout.find('\nActive checkers:')]
return p.returncode, stdout, stderr


Expand Down

0 comments on commit b1de336

Please sign in to comment.