clang-tidy: fix warnings

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2026-04-01 23:46:18 +03:00
parent 8427626e56
commit 087ffb26ba
No known key found for this signature in database
GPG key ID: 55EF5DA53DB36318
5 changed files with 32 additions and 31 deletions

View file

@ -27,7 +27,7 @@
/// qDebug print support for the Version class /// qDebug print support for the Version class
QDebug operator<<(QDebug debug, const Version& v) QDebug operator<<(QDebug debug, const Version& v)
{ {
QDebugStateSaver saver(debug); const QDebugStateSaver saver(debug);
debug.nospace() << "Version{ string: " << v.toString() << ", sections: [ "; debug.nospace() << "Version{ string: " << v.toString() << ", sections: [ ";

View file

@ -29,7 +29,7 @@
// https://git.sleeping.town/exa/FlexVer // https://git.sleeping.town/exa/FlexVer
class Version { class Version {
public: 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; Version() = default;
private: private:

View file

@ -38,59 +38,61 @@
namespace Packwiz { 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; QString realFname = normalizedFname;
if (!index_file.exists()) { if (!indexFile.exists()) {
// Tries to get similar entries // Tries to get similar entries
for (auto& file_name : index_dir.entryList(QDir::Filter::Files)) { for (auto& fileName : indexDir.entryList(QDir::Filter::Files)) {
if (!QString::compare(normalized_fname, file_name, Qt::CaseInsensitive)) { if (QString::compare(normalizedFname, fileName, Qt::CaseInsensitive) == 0) {
real_fname = file_name; realFname = fileName;
break; 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() << "Could not find a match for a valid metadata file!";
qCritical() << "File:" << normalized_fname; qCritical() << "File:" << normalizedFname;
return {}; return {};
} }
} }
return real_fname; return realFname;
} }
// Helpers // Helpers
static inline auto indexFileName(const QString& mod_slug) -> QString auto indexFileName(const QString& modSlug) -> QString
{ {
if (mod_slug.endsWith(".pw.toml")) if (modSlug.endsWith(".pw.toml")) {
return mod_slug; return modSlug;
return QString("%1.pw.toml").arg(mod_slug); }
return QString("%1.pw.toml").arg(modSlug);
} }
// Helper functions for extracting data from the TOML file // 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) { 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 {};
} }
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) { 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 {};
} }
return node.value_or(0); return node->value_or(0);
} }
bool sortMCVersions(const QString& a, const QString& b) bool sortMCVersions(const QString& a, const QString& b)
@ -100,8 +102,9 @@ bool sortMCVersions(const QString& a, const QString& b)
return a < b; return a < b;
} }
return cmp == std::strong_ordering::less; return cmp == std::strong_ordering::less;
}; }
} // namespace
auto V1::createModFormat([[maybe_unused]] const QDir& index_dir, auto V1::createModFormat([[maybe_unused]] const QDir& index_dir,
ModPlatform::IndexedPack& mod_pack, ModPlatform::IndexedPack& mod_pack,
ModPlatform::IndexedVersion& mod_version) -> Mod ModPlatform::IndexedVersion& mod_version) -> Mod

View file

@ -29,8 +29,6 @@ class QDir;
namespace Packwiz { namespace Packwiz {
auto getRealIndexName(const QDir& index_dir, QString normalized_index_name, bool should_match = false) -> QString;
class V1 { class V1 {
public: public:
// can also represent other resources beside loader mods - but this is what packwiz calls it // can also represent other resources beside loader mods - but this is what packwiz calls it

View file

@ -182,13 +182,13 @@ class VersionTest : public QObject {
QCOMPARE(v1 == v2, equal); QCOMPARE(v1 == v2, equal);
} }
void test_strict_weak_order() static void test_strict_weak_order()
{ {
// this tests the strict_weak_order // this tests the strict_weak_order
// https://en.cppreference.com/w/cpp/concepts/strict_weak_order.html // 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 '-' const 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 const Version b("1.10-pre1"); // this is a pre-release is before c that is an actual release
Version c("1.10"); const Version c("1.10");
auto r = [](const Version& a, const Version& b) { return a < b; }; 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); }; auto e = [&r](const Version& a, const Version& b) { return !r(a, b) && !r(b, a); };