Skip to content

Commit 09731c8

Browse files
authored
Merge pull request #2476 from jamescowens/fix_minor_linter
build: Fix several minor linter errors
2 parents 0e9cae1 + c16b448 commit 09731c8

12 files changed

+68
-45
lines changed

src/gridcoin/scraper/http.cpp

+11-11
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void Http::Download(
210210
ScopedFile fp(fsbridge::fopen(destination, "wb"), &fclose);
211211
if (!fp)
212212
throw std::runtime_error(
213-
tfm::format("Error opening target %s: %s (%d)", destination, strerror(errno), errno));
213+
tfm::strformat("Error opening target %s: %s (%d)", destination, strerror(errno), errno));
214214

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

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

227227
std::string Http::GetEtag(
@@ -247,7 +247,7 @@ std::string Http::GetEtag(
247247
curl_slist_free_all(headers);
248248

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

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

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

297297
curl_slist_free_all(headers);
@@ -320,7 +320,7 @@ void Http::DownloadSnapshot()
320320
DownloadStatus.SetSnapshotDownloadFailed(true);
321321

322322
throw std::runtime_error(
323-
tfm::format("Snapshot Downloader: Error opening target %s: %s (%d)",
323+
tfm::strformat("Snapshot Downloader: Error opening target %s: %s (%d)",
324324
destination.string(), strerror(errno), errno));
325325
}
326326

@@ -374,7 +374,7 @@ void Http::DownloadSnapshot()
374374
{
375375
DownloadStatus.SetSnapshotDownloadFailed(true);
376376

377-
throw std::runtime_error(tfm::format("Snapshot Downloader: Failed to download file %s: %s",
377+
throw std::runtime_error(tfm::strformat("Snapshot Downloader: Failed to download file %s: %s",
378378
url, curl_easy_strerror(res)));
379379
}
380380
}
@@ -458,13 +458,13 @@ void Http::EvaluateResponse(int code, const std::string& url)
458458
code == 308)
459459
return;
460460
else if (code == 400)
461-
throw HttpException(tfm::format("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
461+
throw HttpException(tfm::strformat("Server returned a http code of Bad Request <url=%s, code=%d>", url, code));
462462
else if (code == 401)
463-
throw HttpException(tfm::format("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
463+
throw HttpException(tfm::strformat("Server returned a http code of Unauthorized <url=%s, code=%d>", url, code));
464464
else if (code == 403)
465-
throw HttpException(tfm::format("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
465+
throw HttpException(tfm::strformat("Server returned a http code of Forbidden <url=%s, code=%d>", url, code));
466466
else if (code == 404)
467-
throw HttpException(tfm::format("Server returned a http code of Not Found <url=%s, code=%d>", url, code));
467+
throw HttpException(tfm::strformat("Server returned a http code of Not Found <url=%s, code=%d>", url, code));
468468

469-
throw HttpException(tfm::format("Server returned a http code <url=%s, code=%d>", url, code));
469+
throw HttpException(tfm::strformat("Server returned a http code <url=%s, code=%d>", url, code));
470470
}

src/gridcoin/scraper/scraper.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,7 @@ void _log(logattribute eType, const std::string& sCall, const std::string& sMess
10141014
return;
10151015
}
10161016

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

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

@@ -2384,7 +2384,7 @@ EXCLUSIVE_LOCKS_REQUIRED(cs_TeamIDMap)
23842384

23852385
if (!ParseInt64(sTeamID, &nTeamID))
23862386
{
2387-
_log(logattribute::ERR, __func__, tfm::format("Ignoring bad team id for team %s.", sTeamName));
2387+
_log(logattribute::ERR, __func__, tfm::strformat("Ignoring bad team id for team %s.", sTeamName));
23882388
continue;
23892389
}
23902390

src/gridcoin/scraper/scraper_net.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -563,8 +563,8 @@ EXCLUSIVE_LOCKS_REQUIRED(CScraperManifest::cs_mapManifest)
563563
iter->second)));
564564
if (!iter2.second)
565565
{
566-
LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
567-
"hash = %s, already exists. This should not happen.", __func__, nHash.GetHex());
566+
LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
567+
"hash = %s, already exists. This should not happen.", __func__, nHash.GetHex());
568568
}
569569
else
570570
{
@@ -605,8 +605,8 @@ CScraperManifest::DeleteManifest(std::map<uint256, std::shared_ptr<CScraperManif
605605
iter->second)));
606606
if (!iter2.second)
607607
{
608-
LogPrint("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
609-
"hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex());
608+
LogPrintf("WARN: %s: Manifest insertion attempt into pending deleted map failed because an entry with the same "
609+
"hash = %s, already exists. This should not happen.", __func__, iter->first.GetHex());
610610
}
611611
else
612612
{

src/main.cpp

+26-18
Original file line numberDiff line numberDiff line change
@@ -3260,36 +3260,44 @@ void PrintBlockTree() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
32603260
CBlockIndex* pindex = vStack.back().second;
32613261
vStack.pop_back();
32623262

3263+
std::stringstream output;
3264+
32633265
// print split or gap
32643266
if (nCol > nPrevCol)
32653267
{
3266-
for (int i = 0; i < nCol-1; i++)
3267-
LogPrintf("| ");
3268-
LogPrintf("|\\");
3268+
for (int i = 0; i < nCol-1; i++) {
3269+
output << "| \n";
3270+
}
3271+
3272+
output << "|\\\n";
32693273
}
32703274
else if (nCol < nPrevCol)
32713275
{
3272-
for (int i = 0; i < nCol; i++)
3273-
LogPrintf("| ");
3274-
LogPrintf("|");
3275-
}
3276+
for (int i = 0; i < nCol; i++) {
3277+
output << "| \n";
3278+
}
3279+
3280+
output << "|\n";
3281+
}
32763282
nPrevCol = nCol;
32773283

32783284
// print columns
3279-
for (int i = 0; i < nCol; i++)
3280-
LogPrintf("| ");
3285+
for (int i = 0; i < nCol; i++) {
3286+
output << "| \n";
3287+
}
32813288

3282-
// print item
3289+
// print item (and also prepend above formatting)
32833290
CBlock block;
32843291
ReadBlockFromDisk(block, pindex, Params().GetConsensus());
3285-
LogPrintf("%d (%u,%u) %s %08x %s tx %" PRIszu "",
3286-
pindex->nHeight,
3287-
pindex->nFile,
3288-
pindex->nBlockPos,
3289-
block.GetHash(true).ToString().c_str(),
3290-
block.nBits,
3291-
DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
3292-
block.vtx.size());
3292+
LogPrintf("%s%d (%u,%u) %s %08x %s tx %" PRIszu "",
3293+
output.str(),
3294+
pindex->nHeight,
3295+
pindex->nFile,
3296+
pindex->nBlockPos,
3297+
block.GetHash(true).ToString().c_str(),
3298+
block.nBits,
3299+
DateTimeStrFormat("%x %H:%M:%S", block.GetBlockTime()).c_str(),
3300+
block.vtx.size());
32933301

32943302
PrintWallets(block);
32953303

src/miner.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,8 @@ void SplitCoinStakeOutput(CBlock &blocknew, int64_t &nReward, bool &fEnableStake
934934

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

@@ -1327,7 +1328,7 @@ SideStakeAlloc GetSideStakingStatusAndAlloc()
13271328
dSumAllocation += dAllocation;
13281329
if (dSumAllocation > 1.0)
13291330
{
1330-
LogPrintf("WARN: %s: allocation percentage over 100\%, ending sidestake allocations.", __func__);
1331+
LogPrintf("WARN: %s: allocation percentage over 100 percent, ending sidestake allocations.", __func__);
13311332
break;
13321333
}
13331334

src/qt/bitcoin.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,14 @@
4141
#include <QLibraryInfo>
4242
#include <QProcess>
4343

44+
// This eliminates the linter false positive on double include of QtPlugin
45+
#if (defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)) || defined(QT_STATICPLUGIN)
46+
#include <QtPlugin>
47+
#endif
48+
4449
#if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED)
4550
#define _BITCOIN_QT_PLUGINS_INCLUDED
4651
#define __INSURE__
47-
#include <QtPlugin>
4852
Q_IMPORT_PLUGIN(qcncodecs)
4953
Q_IMPORT_PLUGIN(qjpcodecs)
5054
Q_IMPORT_PLUGIN(qtwcodecs)
@@ -53,7 +57,6 @@ Q_IMPORT_PLUGIN(qtaccessiblewidgets)
5357
#endif
5458

5559
#if defined(QT_STATICPLUGIN)
56-
#include <QtPlugin>
5760
#if defined(QT_QPA_PLATFORM_XCB)
5861
Q_IMPORT_PLUGIN(QXcbIntegrationPlugin);
5962
#elif defined(QT_QPA_PLATFORM_WINDOWS)

src/test/gridcoin/mrc_tests.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ struct Setup {
104104
};
105105
} // Anonymous namespace
106106

107-
BOOST_FIXTURE_TEST_SUITE(MRC, Setup)
107+
BOOST_FIXTURE_TEST_SUITE(mrc_tests, Setup)
108108

109109
BOOST_AUTO_TEST_CASE(it_properly_records_blocks)
110110
{

src/tinyformat.h

+8
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,14 @@ std::string format(const std::string &fmt, const Args&... args)
10611061
return oss.str();
10621062
}
10631063

1064+
// This is to make the linter happy because the variadic script/python variadic checker does not deal with
1065+
// overloads.
1066+
template<typename... Args>
1067+
std::string strformat(const std::string &fmt, const Args&... args)
1068+
{
1069+
return format(fmt, args...);
1070+
}
1071+
10641072
} // namespace tinyformat
10651073

10661074
/** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */

src/util/time.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ int64_t MilliTimer::GetStartTime(const std::string& label)
261261
internal_timer = timer_map.at(label);
262262
}
263263
catch (std::out_of_range&) {
264-
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.");
264+
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zero start time.", __func__);
265265
}
266266

267267
return internal_timer.start_time;
@@ -291,7 +291,7 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons
291291
}
292292
catch (std::out_of_range&)
293293
{
294-
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.");
294+
LogPrintf("WARNING: %s: Timer with specified label does not exist. Returning zeroed timer.", __func__);
295295
timer = {};
296296
return timer;
297297
}
@@ -300,8 +300,8 @@ const MilliTimer::timer MilliTimer::GetTimes(const std::string& log_string, cons
300300
// minimize lock time.
301301
if (internal_timer.log)
302302
{
303-
LogPrintf("timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.",
304-
label, log_string, timer.elapsed_time, timer.time_since_last_check);
303+
LogPrintf("INFO: %s: timer %s: %s: elapsed time: %" PRId64 " ms, time since last check: %" PRId64 " ms.",
304+
__func__, label, log_string, timer.elapsed_time, timer.time_since_last_check);
305305
}
306306

307307
return timer;

test/lint/lint-format-strings.py

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(std::string fmt, Params... parameters)"),
2424
("src/wallet/scriptpubkeyman.h", "LogPrintf((\"%s \" + fmt).c_str(), m_storage.GetDisplayName(), parameters...)"),
2525
("src/logging.h", "LogPrintf(const char* fmt, const Args&... args)"),
26+
("src/logging.h", "LogPrint(Category category, const char* format, TINYFORMAT_VARARGS(n))"),
2627
("src/wallet/scriptpubkeyman.h", "WalletLogPrintf(const std::string& fmt, const Params&... parameters)"),
2728
]
2829

test/lint/lint-format-strings.sh

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS=(
1414
"FatalError,0"
1515
"fprintf,1"
1616
"tfm::format,1" # Assuming tfm::::format(std::ostream&, ...
17+
"tfm::strformat,0" # Assuming tfm::::strformat(fmt, ...
1718
"LogConnectFailure,1"
1819
"LogPrint,1"
1920
"LogPrintf,0"

test/lint/lint-spelling.ignore-words.txt

+1
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ fo
2222
dout
2323
nin
2424
inout
25+
smoe

0 commit comments

Comments
 (0)