From 087ffb26ba2703b3e285d4f6fb43249d65db5a4e Mon Sep 17 00:00:00 2001 From: Trial97 Date: Wed, 1 Apr 2026 23:46:18 +0300 Subject: [PATCH] clang-tidy: fix warnings Signed-off-by: Trial97 --- launcher/Version.cpp | 2 +- launcher/Version.h | 2 +- launcher/modplatform/packwiz/Packwiz.cpp | 49 +++++++++++++----------- launcher/modplatform/packwiz/Packwiz.h | 2 - tests/Version_test.cpp | 8 ++-- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/launcher/Version.cpp b/launcher/Version.cpp index ebe31b12a..d5496ce1c 100644 --- a/launcher/Version.cpp +++ b/launcher/Version.cpp @@ -27,7 +27,7 @@ /// qDebug print support for the Version class QDebug operator<<(QDebug debug, const Version& v) { - QDebugStateSaver saver(debug); + const QDebugStateSaver saver(debug); debug.nospace() << "Version{ string: " << v.toString() << ", sections: [ "; diff --git a/launcher/Version.h b/launcher/Version.h index d123f8348..c0f70f487 100644 --- a/launcher/Version.h +++ b/launcher/Version.h @@ -29,7 +29,7 @@ // https://git.sleeping.town/exa/FlexVer class Version { public: - Version(QString str) : m_string(std::move(str)) { parse(); } + Version(QString str) : m_string(std::move(str)) { parse(); } // NOLINT(hicpp-explicit-conversions) Version() = default; private: diff --git a/launcher/modplatform/packwiz/Packwiz.cpp b/launcher/modplatform/packwiz/Packwiz.cpp index aa1f01601..4d162a90d 100644 --- a/launcher/modplatform/packwiz/Packwiz.cpp +++ b/launcher/modplatform/packwiz/Packwiz.cpp @@ -38,59 +38,61 @@ namespace Packwiz { -auto getRealIndexName(const QDir& index_dir, QString normalized_fname, bool should_find_match) -> QString +namespace { +auto getRealIndexName(const QDir& indexDir, const QString& normalizedFname, bool shouldFindMatch = false) -> QString { - QFile index_file(index_dir.absoluteFilePath(normalized_fname)); + const QFile indexFile(indexDir.absoluteFilePath(normalizedFname)); - QString real_fname = normalized_fname; - if (!index_file.exists()) { + QString realFname = normalizedFname; + if (!indexFile.exists()) { // Tries to get similar entries - for (auto& file_name : index_dir.entryList(QDir::Filter::Files)) { - if (!QString::compare(normalized_fname, file_name, Qt::CaseInsensitive)) { - real_fname = file_name; + for (auto& fileName : indexDir.entryList(QDir::Filter::Files)) { + if (QString::compare(normalizedFname, fileName, Qt::CaseInsensitive) == 0) { + realFname = fileName; break; } } - if (should_find_match && !QString::compare(normalized_fname, real_fname, Qt::CaseSensitive)) { + if (shouldFindMatch && (QString::compare(normalizedFname, realFname, Qt::CaseSensitive) == 0)) { qCritical() << "Could not find a match for a valid metadata file!"; - qCritical() << "File:" << normalized_fname; + qCritical() << "File:" << normalizedFname; return {}; } } - return real_fname; + return realFname; } // Helpers -static inline auto indexFileName(const QString& mod_slug) -> QString +auto indexFileName(const QString& modSlug) -> QString { - if (mod_slug.endsWith(".pw.toml")) - return mod_slug; - return QString("%1.pw.toml").arg(mod_slug); + if (modSlug.endsWith(".pw.toml")) { + return modSlug; + } + return QString("%1.pw.toml").arg(modSlug); } // Helper functions for extracting data from the TOML file -auto stringEntry(toml::table table, QString entry_name) -> QString +auto stringEntry(toml::table table, const QString& entryName) -> QString { - auto node = table[StringUtils::toStdString(entry_name)]; + auto* node = table.get(StringUtils::toStdString(entryName)); if (!node) { - qDebug() << "Failed to read str property '" + entry_name + "' in mod metadata."; + qDebug() << "Failed to read str property '" + entryName + "' in mod metadata."; return {}; } - return node.value_or(""); + return node->value_or(""); } -auto intEntry(toml::table table, QString entry_name) -> int +auto intEntry(toml::table table, const QString& entryName) -> int { - auto node = table[StringUtils::toStdString(entry_name)]; + auto* node = table.get(StringUtils::toStdString(entryName)); if (!node) { - qDebug() << "Failed to read int property '" + entry_name + "' in mod metadata."; + qDebug() << "Failed to read int property '" + entryName + "' in mod metadata."; return {}; } - return node.value_or(0); + return node->value_or(0); } bool sortMCVersions(const QString& a, const QString& b) @@ -100,8 +102,9 @@ bool sortMCVersions(const QString& a, const QString& b) return a < b; } return cmp == std::strong_ordering::less; -}; +} +} // namespace auto V1::createModFormat([[maybe_unused]] const QDir& index_dir, ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedVersion& mod_version) -> Mod diff --git a/launcher/modplatform/packwiz/Packwiz.h b/launcher/modplatform/packwiz/Packwiz.h index b5b8894f3..b5b817755 100644 --- a/launcher/modplatform/packwiz/Packwiz.h +++ b/launcher/modplatform/packwiz/Packwiz.h @@ -29,8 +29,6 @@ class QDir; namespace Packwiz { -auto getRealIndexName(const QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString; - class V1 { public: // can also represent other resources beside loader mods - but this is what packwiz calls it diff --git a/tests/Version_test.cpp b/tests/Version_test.cpp index f6ac6f951..3e52f4eb9 100644 --- a/tests/Version_test.cpp +++ b/tests/Version_test.cpp @@ -182,13 +182,13 @@ class VersionTest : public QObject { QCOMPARE(v1 == v2, equal); } - void test_strict_weak_order() + static void test_strict_weak_order() { // this tests the strict_weak_order // https://en.cppreference.com/w/cpp/concepts/strict_weak_order.html - Version a("1.10 Pre-Release 1"); // this is a pre-relese is before b because ' ' is lower than '-' - Version b("1.10-pre1"); // this is a pre-release is before c that is an actual release - Version c("1.10"); + const Version a("1.10 Pre-Release 1"); // this is a pre-relese is before b because ' ' is lower than '-' + const Version b("1.10-pre1"); // this is a pre-release is before c that is an actual release + const Version c("1.10"); auto r = [](const Version& a, const Version& b) { return a < b; }; auto e = [&r](const Version& a, const Version& b) { return !r(a, b) && !r(b, a); };