Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Fix several minor linter errors #2476

Merged
22 changes: 11 additions & 11 deletions src/gridcoin/scraper/http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void Http::Download(
ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose);
if (!fp)
throw std::runtime_error(
tfm::format("Error opening target %s: %s (%d)", destination, strerror(errno), errno));
tfm::strformat("Error opening target %s: %s (%d)", destination, strerror(errno), errno));

std::string buffer;
ScopedCurl curl = GetContext();
Expand All @@ -221,7 +221,7 @@ void Http::Download(

CURLcode res = curl_easy_perform(curl.get());
if (res > 0)
throw std::runtime_error(tfm::format("Failed to download file %s: %s", url, curl_easy_strerror(res)));
throw std::runtime_error(tfm::strformat("Failed to download file %s: %s", url, curl_easy_strerror(res)));
}

std::string Http::GetEtag(
Expand All @@ -247,7 +247,7 @@ std::string Http::GetEtag(
curl_slist_free_all(headers);

if (res > 0)
throw std::runtime_error(tfm::format("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res)));
throw std::runtime_error(tfm::strformat("Failed to get ETag for URL %s: %s", url, curl_easy_strerror(res)));

// Validate HTTP return code.
long response_code;
Expand Down Expand Up @@ -291,7 +291,7 @@ std::string Http::GetLatestVersionResponse()
CURLcode res = curl_easy_perform(curl.get());

if (res > 0)
throw std::runtime_error(tfm::format("Failed to get version response from URL %s: %s",
throw std::runtime_error(tfm::strformat("Failed to get version response from URL %s: %s",
url, curl_easy_strerror(res)));

curl_slist_free_all(headers);
Expand Down Expand Up @@ -320,7 +320,7 @@ void Http::DownloadSnapshot()
DownloadStatus.SetSnapshotDownloadFailed(true);

throw std::runtime_error(
tfm::format("Snapshot Downloader: Error opening target %s: %s (%d)",
tfm::strformat("Snapshot Downloader: Error opening target %s: %s (%d)",
destination.string(), strerror(errno), errno));
}

Expand Down Expand Up @@ -374,7 +374,7 @@ void Http::DownloadSnapshot()
{
DownloadStatus.SetSnapshotDownloadFailed(true);

throw std::runtime_error(tfm::format("Snapshot Downloader: Failed to download file %s: %s",
throw std::runtime_error(tfm::strformat("Snapshot Downloader: Failed to download file %s: %s",
url, curl_easy_strerror(res)));
}
}
Expand Down Expand Up @@ -458,13 +458,13 @@ void Http::EvaluateResponse(int code, const std::string& url)
code == 308)
return;
else if (code == 400)
throw HttpException(tfm::format("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
throw HttpException(tfm::strformat("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
else if (code == 401)
throw HttpException(tfm::format("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
throw HttpException(tfm::strformat("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
else if (code == 403)
throw HttpException(tfm::format("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
throw HttpException(tfm::strformat("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
else if (code == 404)
throw HttpException(tfm::format("Server returned a http code of Not Found <url=%s, code=%d>", url, code));
throw HttpException(tfm::strformat("Server returned a http code of Not Found <url=%s, code=%d>", url, code));

throw HttpException(tfm::format("Server returned a http code <url=%s, code=%d>", url, code));
throw HttpException(tfm::strformat("Server returned a http code <url=%s, code=%d>", url, code));
}
6 changes: 3 additions & 3 deletions src/gridcoin/scraper/scraper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,7 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
return;
}

sOut = tfm::format("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage);
sOut = tfm::strformat("%s [%s] <%s> : %s", DateTimeStrFormat("%x %H:%M:%S", GetAdjustedTime()), sType, sCall, sMessage);

// This snoops the SCRAPER category setting from the main logger, and uses it as a conditional for the scraper log output.
// Logs will be posted to the scraper log when the category is set OR it is not an INFO level... (i.e. critical, warning,
Expand Down Expand Up @@ -1320,7 +1320,7 @@ void ApplyCache(const std::string& key, T& result)
}
catch (const std::exception&)
{
_log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::format("Ignoring bad AppCache entry for %s.", key));
_log(logattribute::ERR, "ScraperApplyAppCacheEntries", tfm::strformat("Ignoring bad AppCache entry for %s.", key));
}
}

Expand Down Expand Up @@ -2384,7 +2384,7 @@ EXCLUSIVE_LOCKS_REQUIRED(cs_TeamIDMap)

if (!ParseInt64(sTeamID, &nTeamID))
{
_log(logattribute::ERR, __func__, tfm::format("Ignoring bad team id for team %s.", sTeamName));
_log(logattribute::ERR, __func__, tfm::strformat("Ignoring bad team id for team %s.", sTeamName));
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions src/gridcoin/scraper/scraper_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,8 @@ EXCLUSIVE_LOCKS_REQUIRED(CScraperManifest::cs_mapManifest)
iter->second)));
if (!iter2.second)
{
LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
"hash = %s, already exists. This should not happen.", __func__, nHash.GetHex());
LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
"hash = %s, already exists. This should not happen.", __func__, nHash.GetHex());
}
else
{
Expand Down Expand Up @@ -605,8 +605,8 @@ CScraperManifest::DeleteManifest(std::map<uint256, std::shared_ptr<CScraperManif
iter->second)));
if (!iter2.second)
{
LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
"hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex());
LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
"hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex());
}
else
{
Expand Down
44 changes: 26 additions & 18 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3260,36 +3260,44 @@ void PrintBlockTree() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CBlockIndex* pindex = vStack.back().second;
vStack.pop_back();

std::stringstream output;

// print split or gap
if (nCol > nPrevCol)
{
for (int i = 0; i < nCol-1; i++)
LogPrintf("| ");
LogPrintf("|\\");
for (int i = 0; i < nCol-1; i++) {
output << "| \n";
}

output << "|\\\n";
}
else if (nCol < nPrevCol)
{
for (int i = 0; i < nCol; i++)
LogPrintf("| ");
LogPrintf("|");
}
for (int i = 0; i < nCol; i++) {
output << "| \n";
}

output << "|\n";
}
nPrevCol = nCol;

// print columns
for (int i = 0; i < nCol; i++)
LogPrintf("| ");
for (int i = 0; i < nCol; i++) {
output << "| \n";
}

// print item
// print item (and also prepend above formatting)
CBlock block;
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
LogPrintf("%d (%u,%u) %s %08x %s tx %" PRIszu "",
pindex->nHeight,
pindex->nFile,
pindex->nBlockPos,
block.GetHash(true).ToString().c_str(),
block.nBits,
DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
block.vtx.size());
LogPrintf("%s%d (%u,%u) %s %08x %s tx %" PRIszu "",
output.str(),
pindex->nHeight,
pindex->nFile,
pindex->nBlockPos,
block.GetHash(true).ToString().c_str(),
block.nBits,
DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
block.vtx.size());

PrintWallets(block);

Expand Down
5 changes: 3 additions & 2 deletions src/miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake

if (dSumAllocation + iterSideStake->second > 1.0)
{
LogPrintf("WARN: SplitCoinStakeOutput: allocation percentage over 100\%, ending sidestake allocations.");
LogPrintf("WARN: SplitCoinStakeOutput: allocation percentage over 100 percent, "
"ending sidestake allocations.");
break;
}

Expand Down Expand Up @@ -1327,7 +1328,7 @@ SideStakeAlloc GetSideStakingStatusAndAlloc()
dSumAllocation += dAllocation;
if (dSumAllocation > 1.0)
{
LogPrintf("WARN: %s: allocation percentage over 100\%, ending sidestake allocations.", __func__);
LogPrintf("WARN: %s: allocation percentage over 100 percent, ending sidestake allocations.", __func__);
break;
}

Expand Down
7 changes: 5 additions & 2 deletions src/qt/bitcoin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
#include <QLibraryInfo>
#include <QProcess>

// This eliminates the linter false positive on double include of QtPlugin
#if (defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)) || defined(QT_STATICPLUGIN)
#include <QtPlugin>
#endif

#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
#define _BITCOIN_QT_PLUGINS_INCLUDED
#define __INSURE__
#include <QtPlugin>
Q_IMPORT_PLUGIN(qcncodecs)
Q_IMPORT_PLUGIN(qjpcodecs)
Q_IMPORT_PLUGIN(qtwcodecs)
Expand All @@ -53,7 +57,6 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets)
#endif

#if defined(QT_STATICPLUGIN)
#include <QtPlugin>
#if defined(QT_QPA_PLATFORM_XCB)
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
#elif defined(QT_QPA_PLATFORM_WINDOWS)
Expand Down
2 changes: 1 addition & 1 deletion src/test/gridcoin/mrc_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ struct Setup {
};
} // Anonymous namespace

BOOST_FIXTURE_TEST_SUITE(MRC, Setup)
BOOST_FIXTURE_TEST_SUITE(mrc_tests, Setup)

BOOST_AUTO_TEST_CASE(it_properly_records_blocks)
{
Expand Down
8 changes: 8 additions & 0 deletions src/tinyformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,14 @@ std::string format(const std::string &fmt, const Args&... args)
return oss.str();
}

// This is to make the linter happy because it the variadic script/python variadic checker does not deal with
jamescowens marked this conversation as resolved.
Show resolved Hide resolved
// overloads.
template<typename... Args>
std::string strformat(const std::string &fmt, const Args&... args)
{
return format(fmt, args...);
}

} // namespace tinyformat

/** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */
Expand Down
8 changes: 4 additions & 4 deletions src/util/time.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ int64_t MilliTimer::GetStartTime(const std::string& label)
internal_timer = timer_map.at(label);
}
catch (std::out_of_range&) {
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.");
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.", __func__);
}

return internal_timer.start_time;
Expand Down Expand Up @@ -291,7 +291,7 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons
}
catch (std::out_of_range&)
{
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.");
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.", __func__);
timer = {};
return timer;
}
Expand All @@ -300,8 +300,8 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons
// minimize lock time.
if (internal_timer.log)
{
LogPrintf("timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.",
label, log_string, timer.elapsed_time, timer.time_since_last_check);
LogPrintf("INFO: %s: timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.",
__func__, label, log_string, timer.elapsed_time, timer.time_since_last_check);
}

return timer;
Expand Down
1 change: 1 addition & 0 deletions test/lint/lint-format-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + fmt).c_str(), m_storage.GetDisplayName(), parameters...)"),
("src/logging.h", "LogPrintf(const char* fmt, const Args&... args)"),
("src/logging.h", "LogPrint(Category category, const char* format, TINYFORMAT_VARARGS(n))"),
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const std::string& fmt, const Params&... parameters)"),
]

Expand Down
1 change: 1 addition & 0 deletions test/lint/lint-format-strings.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=(
"FatalError,0"
"fprintf,1"
"tfm::format,1" # Assuming tfm::::format(std::ostream&, ...
"tfm::strformat,0" # Assuming tfm::::strformat(fmt, ...
"LogConnectFailure,1"
"LogPrint,1"
"LogPrintf,0"
Expand Down
1 change: 1 addition & 0 deletions test/lint/lint-spelling.ignore-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ fo
dout
nin
inout
smoe