diff --git a/.clang-tidy b/.clang-tidy index dbf9fbd7..645c9c05 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -10,6 +10,7 @@ Checks: - '-cppcoreguidelines-pro-type-reinterpret-cast' - '-misc-include-cleaner' - '-misc-non-private-member-variables-in-classes' + - '-misc-use-anonymous-namespace' - '-modernize-return-braced-init-list' - '-modernize-use-trailing-return-type' FormatStyle: 'file' diff --git a/scwx-qt/source/scwx/qt/manager/marker_manager.cpp b/scwx-qt/source/scwx/qt/manager/marker_manager.cpp index ea21b211..8af310ec 100644 --- a/scwx-qt/source/scwx/qt/manager/marker_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/marker_manager.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -70,7 +71,7 @@ public: class MarkerManager::Impl::MarkerRecord { public: - MarkerRecord(const types::MarkerInfo& info) : markerInfo_ {info} {} + MarkerRecord(types::MarkerInfo info) : markerInfo_ {std::move(info)} {} const types::MarkerInfo& toMarkerInfo() { return markerInfo_; } diff --git a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp index 2300a7b1..77b8143b 100644 --- a/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/text_event_manager.cpp @@ -241,7 +241,7 @@ void TextEventManager::SelectTime( boost::asio::post( p->threadPool_, - [=, this]() + [this]() { try { @@ -259,7 +259,7 @@ void TextEventManager::SelectTime( date < p->archiveLimit_; }); - std::unique_lock lock {p->archiveMutex_}; + const std::unique_lock lock {p->archiveMutex_}; p->UpdateArchiveDates(dates); p->ListArchives(dates); @@ -382,7 +382,7 @@ void TextEventManager::Impl::ListArchives(DateRange dates) auto productEntries = provider::IemApiProvider::ListTextProducts( dateArray | ranges::views::all, kEmptyRange_, kPilsView_); - std::unique_lock lock {unloadedProductMapMutex_}; + const std::unique_lock lock {unloadedProductMapMutex_}; if (productEntries.has_value()) { diff --git a/scwx-qt/source/scwx/qt/manager/timeline_manager.hpp b/scwx-qt/source/scwx/qt/manager/timeline_manager.hpp index bbff19f4..054a8201 100644 --- a/scwx-qt/source/scwx/qt/manager/timeline_manager.hpp +++ b/scwx-qt/source/scwx/qt/manager/timeline_manager.hpp @@ -24,7 +24,7 @@ public: static std::shared_ptr Instance(); - std::chrono::system_clock::time_point GetSelectedTime() const; + [[nodiscard]] std::chrono::system_clock::time_point GetSelectedTime() const; void SetMapCount(std::size_t mapCount); diff --git a/scwx-qt/source/scwx/qt/manager/update_manager.cpp b/scwx-qt/source/scwx/qt/manager/update_manager.cpp index 5910fcaf..05a9c0d1 100644 --- a/scwx-qt/source/scwx/qt/manager/update_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/update_manager.cpp @@ -126,7 +126,7 @@ size_t UpdateManager::Impl::PopulateReleases() // Successful REST API query if (r.status_code == 200) { - boost::json::value json = util::json::ReadJsonString(r.text); + const boost::json::value json = util::json::ReadJsonString(r.text); if (json == nullptr) { logger_->warn("Response not JSON: {}", r.header["content-type"]); diff --git a/test/source/scwx/awips/wmo_header.test.cpp b/test/source/scwx/awips/wmo_header.test.cpp index bdc4406f..17cd9706 100644 --- a/test/source/scwx/awips/wmo_header.test.cpp +++ b/test/source/scwx/awips/wmo_header.test.cpp @@ -16,7 +16,7 @@ TEST(WmoHeader, WmoFields) { std::stringstream ss {kWmoHeaderSample_}; WmoHeader header; - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); EXPECT_EQ(valid, true); EXPECT_EQ(header.sequence_number(), "887"); @@ -40,7 +40,7 @@ TEST(WmoHeader, DateHintBeforeParse) WmoHeader header; header.SetDateHint(2022y / October); - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); EXPECT_EQ(valid, true); EXPECT_EQ(header.GetDateTime(), @@ -54,7 +54,7 @@ TEST(WmoHeader, DateHintAfterParse) std::stringstream ss {kWmoHeaderSample_}; WmoHeader header; - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); header.SetDateHint(2022y / October); EXPECT_EQ(valid, true); @@ -69,7 +69,7 @@ TEST(WmoHeader, EndTimeHintSameMonth) std::stringstream ss {kWmoHeaderSample_}; WmoHeader header; - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); auto endTimeHint = sys_days {2022y / October / 29d} + 0h + 0min + 0s; @@ -85,7 +85,7 @@ TEST(WmoHeader, EndTimeHintPreviousMonth) std::stringstream ss {kWmoHeaderSample_}; WmoHeader header; - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); auto endTimeHint = sys_days {2022y / October / 27d} + 0h + 0min + 0s; @@ -101,7 +101,7 @@ TEST(WmoHeader, EndTimeHintPreviousYear) std::stringstream ss {kWmoHeaderSample_}; WmoHeader header; - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); auto endTimeHint = sys_days {2022y / January / 27d} + 0h + 0min + 0s; @@ -118,7 +118,7 @@ TEST(WmoHeader, EndTimeHintIgnored) WmoHeader header; header.SetDateHint(2022y / October); - bool valid = header.Parse(ss); + const bool valid = header.Parse(ss); auto endTimeHint = sys_days {2020y / January / 1d} + 0h + 0min + 0s; diff --git a/test/source/scwx/provider/iem_api_provider.test.cpp b/test/source/scwx/provider/iem_api_provider.test.cpp index 4f964b81..0cf133e0 100644 --- a/test/source/scwx/provider/iem_api_provider.test.cpp +++ b/test/source/scwx/provider/iem_api_provider.test.cpp @@ -2,9 +2,7 @@ #include -namespace scwx -{ -namespace provider +namespace scwx::provider { TEST(IemApiProviderTest, ListTextProducts) @@ -12,11 +10,9 @@ TEST(IemApiProviderTest, ListTextProducts) using namespace std::chrono; using sys_days = time_point; - IemApiProvider provider {}; - auto date = sys_days {2023y / March / 25d}; - auto torProducts = provider.ListTextProducts(date, {}, "TOR"); + auto torProducts = IemApiProvider::ListTextProducts(date, {}, "TOR"); ASSERT_EQ(torProducts.has_value(), true); EXPECT_EQ(torProducts.value().size(), 35); @@ -40,9 +36,7 @@ TEST(IemApiProviderTest, LoadTextProducts) "202303252015-KFFC-WFUS52-TORFFC", "202303311942-KLZK-WWUS54-SVSLZK"}; - IemApiProvider provider {}; - - auto textProducts = provider.LoadTextProducts(productIds); + auto textProducts = IemApiProvider::LoadTextProducts(productIds); EXPECT_EQ(textProducts.size(), 3); @@ -60,5 +54,4 @@ TEST(IemApiProviderTest, LoadTextProducts) } } -} // namespace provider -} // namespace scwx +} // namespace scwx::provider diff --git a/test/source/scwx/provider/warnings_provider.test.cpp b/test/source/scwx/provider/warnings_provider.test.cpp index de315b4b..c1c824da 100644 --- a/test/source/scwx/provider/warnings_provider.test.cpp +++ b/test/source/scwx/provider/warnings_provider.test.cpp @@ -18,9 +18,9 @@ TEST_P(WarningsProviderTest, LoadUpdatedFiles) { WarningsProvider provider(GetParam()); - std::chrono::sys_time now = + const std::chrono::sys_time now = std::chrono::floor(std::chrono::system_clock::now()); - std::chrono::sys_time startTime = + const std::chrono::sys_time startTime = now - std::chrono::days {3}; auto updatedFiles = provider.LoadUpdatedFiles(startTime); diff --git a/wxdata/include/scwx/awips/text_product_message.hpp b/wxdata/include/scwx/awips/text_product_message.hpp index 6830f91a..373dc223 100644 --- a/wxdata/include/scwx/awips/text_product_message.hpp +++ b/wxdata/include/scwx/awips/text_product_message.hpp @@ -96,7 +96,7 @@ public: TextProductMessage(TextProductMessage&&) noexcept; TextProductMessage& operator=(TextProductMessage&&) noexcept; - boost::uuids::uuid uuid() const; + [[nodiscard]] boost::uuids::uuid uuid() const; std::string message_content() const; std::shared_ptr wmo_header() const; std::vector mnd_header() const; diff --git a/wxdata/source/scwx/awips/text_product_message.cpp b/wxdata/source/scwx/awips/text_product_message.cpp index f8716b2b..53ec502d 100644 --- a/wxdata/source/scwx/awips/text_product_message.cpp +++ b/wxdata/source/scwx/awips/text_product_message.cpp @@ -593,8 +593,8 @@ std::optional TryParseVtecString(std::istream& is) if (RE2::PartialMatch(line, *rePVtecString)) { - vtec = Vtec(); - bool vtecValid = vtec->pVtec_.Parse(line); + vtec = Vtec(); + const bool vtecValid = vtec->pVtec_.Parse(line); isBegin = is.tellg(); diff --git a/wxdata/source/scwx/awips/wmo_header.cpp b/wxdata/source/scwx/awips/wmo_header.cpp index fad1231b..f89db609 100644 --- a/wxdata/source/scwx/awips/wmo_header.cpp +++ b/wxdata/source/scwx/awips/wmo_header.cpp @@ -143,9 +143,11 @@ std::chrono::sys_time WmoHeader::GetDateTime( { std::chrono::sys_time wmoDateTime {}; - if (p->absoluteDateTime_.has_value()) + const auto absoluteDateTime = p->absoluteDateTime_; + + if (absoluteDateTime.has_value()) { - wmoDateTime = p->absoluteDateTime_.value(); + wmoDateTime = absoluteDateTime.value(); } else if (endTimeHint.has_value()) { @@ -160,8 +162,8 @@ std::chrono::sys_time WmoHeader::GetDateTime( { using namespace std::chrono; - auto endDays = floor(endTimeHint.value()); - year_month_day endDate {endDays}; + const auto endDays = floor(endTimeHint.value()); + const year_month_day endDate {endDays}; // Combine end date year and month with WMO date time wmoDateTime = diff --git a/wxdata/source/scwx/provider/iem_api_provider.cpp b/wxdata/source/scwx/provider/iem_api_provider.cpp index c3d7dce0..85c37ec5 100644 --- a/wxdata/source/scwx/provider/iem_api_provider.cpp +++ b/wxdata/source/scwx/provider/iem_api_provider.cpp @@ -50,9 +50,9 @@ IemApiProvider::ListTextProducts(std::chrono::sys_days date, std::optional optionalCccc, std::optional optionalPil) { - std::string_view cccc = + const std::string_view cccc = optionalCccc.has_value() ? optionalCccc.value() : std::string_view {}; - std::string_view pil = + const std::string_view pil = optionalPil.has_value() ? optionalPil.value() : std::string_view {}; const auto dateArray = std::array {date}; @@ -72,7 +72,7 @@ IemApiProvider::ProcessTextProductLists( { auto response = asyncResponse.get(); - boost::json::value json = util::json::ReadJsonString(response.text); + const boost::json::value json = util::json::ReadJsonString(response.text); if (response.status_code == cpr::status::HTTP_OK) { @@ -161,7 +161,7 @@ IemApiProvider::ProcessTextProductFiles( { // Load file auto& productId = asyncResponse.first; - std::shared_ptr textProductFile { + const std::shared_ptr textProductFile { std::make_shared()}; std::istringstream responseBody {response.text}; if (textProductFile->LoadData(productId, responseBody)) diff --git a/wxdata/source/scwx/provider/warnings_provider.cpp b/wxdata/source/scwx/provider/warnings_provider.cpp index f0d6b8dd..78eb687c 100644 --- a/wxdata/source/scwx/provider/warnings_provider.cpp +++ b/wxdata/source/scwx/provider/warnings_provider.cpp @@ -5,6 +5,7 @@ // Enable chrono formatters #ifndef __cpp_lib_format +// NOLINTNEXTLINE(bugprone-reserved-identifier, cppcoreguidelines-macro-usage) # define __cpp_lib_format 202110L #endif @@ -106,7 +107,7 @@ WarningsProvider::LoadUpdatedFiles( asyncCallbacks; std::vector> updatedFiles; - std::chrono::sys_time now = + const std::chrono::sys_time now = std::chrono::floor(std::chrono::system_clock::now()); std::chrono::sys_time currentHour = (startTime != std::chrono::sys_time {}) ? @@ -130,7 +131,8 @@ WarningsProvider::LoadUpdatedFiles( { if (headResponse.status_code == cpr::status::HTTP_OK) { - bool updated = p->UpdateFileRecord(headResponse, filename); + const bool updated = + p->UpdateFileRecord(headResponse, filename); if (updated) { @@ -173,7 +175,7 @@ WarningsProvider::LoadUpdatedFiles( logger_->debug("Loading file: {}", filename); // Load file - std::shared_ptr textProductFile { + const std::shared_ptr textProductFile { std::make_shared()}; std::istringstream responseBody {response.text}; if (textProductFile->LoadData(filename, responseBody)) @@ -218,7 +220,7 @@ bool WarningsProvider::Impl::UpdateFileRecord(const cpr::Response& response, lastModified = lastModifiedIt->second; } - std::unique_lock lock(filesMutex_); + const std::unique_lock lock(filesMutex_); auto it = files_.find(filename); if (it != files_.cend()) diff --git a/wxdata/source/scwx/util/time.cpp b/wxdata/source/scwx/util/time.cpp index 20c6121d..563aea1b 100644 --- a/wxdata/source/scwx/util/time.cpp +++ b/wxdata/source/scwx/util/time.cpp @@ -21,9 +21,7 @@ # include #endif -namespace scwx -{ -namespace util +namespace scwx::util { static const std::string logPrefix_ = "scwx::util::time"; @@ -48,6 +46,7 @@ std::chrono::system_clock::time_point TimePoint(uint32_t modifiedJulianDate, using sys_days = time_point; constexpr auto epoch = sys_days {1969y / December / 31d}; + // NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers): literals are used return epoch + (modifiedJulianDate * 24h) + std::chrono::milliseconds {milliseconds}; } @@ -154,5 +153,4 @@ template std::optional> TryParseDateTime(const std::string& dateTimeFormat, const std::string& str); -} // namespace util -} // namespace scwx +} // namespace scwx::util