From d4030ec1bc50948e7939c8d42d806e8137e2c5c0 Mon Sep 17 00:00:00 2001 From: Sergio Date: Mon, 3 Nov 2025 09:58:19 +0100 Subject: [PATCH] linter --- source/core/resources/resource_helper.cpp | 26 +++++++++++------------ source/core/resources/resource_helper.hpp | 6 ++---- source/core/resources/resource_loader.cpp | 4 ++-- source/core/resources/resource_loader.hpp | 20 ++++++++--------- 4 files changed, 26 insertions(+), 30 deletions(-) diff --git a/source/core/resources/resource_helper.cpp b/source/core/resources/resource_helper.cpp index ef57270..7a0776f 100644 --- a/source/core/resources/resource_helper.cpp +++ b/source/core/resources/resource_helper.cpp @@ -10,8 +10,7 @@ #include "resource_loader.hpp" -namespace Jdd { -namespace ResourceHelper { +namespace Jdd::ResourceHelper { static bool resource_system_initialized = false; @@ -106,7 +105,7 @@ auto getPackPath(const std::string& asset_path) -> std::string { std::string path = asset_path; // Convert backslashes to forward slashes - std::replace(path.begin(), path.end(), '\\', '/'); + std::ranges::replace(path, '\\', '/'); // Remove leading slashes while (!path.empty() && path[0] == '/') { @@ -114,25 +113,25 @@ auto getPackPath(const std::string& asset_path) -> std::string { } // Remove "./" prefix if present - if (path.find("./") == 0) { + if (path.starts_with("./")) { path = path.substr(2); } // Remove "../" prefixes (for macOS bundle paths in development) - while (path.find("../") == 0) { + while (path.starts_with("../")) { path = path.substr(3); } // Remove "Resources/" prefix if present (for macOS bundle) - const std::string resources_prefix = "Resources/"; - if (path.find(resources_prefix) == 0) { - path = path.substr(resources_prefix.length()); + const std::string RESOURCES_PREFIX = "Resources/"; + if (path.starts_with(RESOURCES_PREFIX)) { + path = path.substr(RESOURCES_PREFIX.length()); } // Remove "data/" prefix if present - const std::string data_prefix = "data/"; - if (path.find(data_prefix) == 0) { - path = path.substr(data_prefix.length()); + const std::string DATA_PREFIX = "data/"; + if (path.starts_with(DATA_PREFIX)) { + path = path.substr(DATA_PREFIX.length()); } return path; @@ -141,7 +140,7 @@ auto getPackPath(const std::string& asset_path) -> std::string { // Check if file should use resource pack auto shouldUseResourcePack(const std::string& filepath) -> bool { std::string path = filepath; - std::replace(path.begin(), path.end(), '\\', '/'); + std::ranges::replace(path, '\\', '/'); // Don't use pack for most config files (except config/assets.txt which is loaded // directly via ResourceLoader::loadAssetsConfig() in release builds) @@ -174,5 +173,4 @@ auto isPackLoaded() -> bool { return ResourceLoader::get().isPackLoaded(); } -} // namespace ResourceHelper -} // namespace Jdd +} // namespace Jdd::ResourceHelper diff --git a/source/core/resources/resource_helper.hpp b/source/core/resources/resource_helper.hpp index 6d2c864..bb5ba4a 100644 --- a/source/core/resources/resource_helper.hpp +++ b/source/core/resources/resource_helper.hpp @@ -8,8 +8,7 @@ #include #include -namespace Jdd { -namespace ResourceHelper { +namespace Jdd::ResourceHelper { // Initialize the resource system // pack_file: Path to resources.pack @@ -37,7 +36,6 @@ auto shouldUseResourcePack(const std::string& filepath) -> bool; // Check if pack is loaded auto isPackLoaded() -> bool; -} // namespace ResourceHelper -} // namespace Jdd +} // namespace Jdd::ResourceHelper #endif // RESOURCE_HELPER_HPP diff --git a/source/core/resources/resource_loader.cpp b/source/core/resources/resource_loader.cpp index 65356df..f4fb411 100644 --- a/source/core/resources/resource_loader.cpp +++ b/source/core/resources/resource_loader.cpp @@ -11,8 +11,8 @@ namespace Jdd { // Get singleton instance auto ResourceLoader::get() -> ResourceLoader& { - static ResourceLoader instance; - return instance; + static ResourceLoader instance_; + return instance_; } // Initialize with a pack file diff --git a/source/core/resources/resource_loader.hpp b/source/core/resources/resource_loader.hpp index 60edb7d..80bc4d1 100644 --- a/source/core/resources/resource_loader.hpp +++ b/source/core/resources/resource_loader.hpp @@ -28,30 +28,30 @@ class ResourceLoader { auto resourceExists(const std::string& filename) -> bool; // Check if pack is loaded - auto isPackLoaded() const -> bool; + [[nodiscard]] auto isPackLoaded() const -> bool; // Get pack statistics - auto getPackResourceCount() const -> size_t; + [[nodiscard]] auto getPackResourceCount() const -> size_t; // Validate pack integrity (checksum) - auto validatePack() const -> bool; + [[nodiscard]] auto validatePack() const -> bool; // Load assets.txt from pack (for release builds) - auto loadAssetsConfig() const -> std::string; + [[nodiscard]] auto loadAssetsConfig() const -> std::string; // Cleanup void shutdown(); + // Disable copy/move + ResourceLoader(const ResourceLoader&) = delete; + auto operator=(const ResourceLoader&) -> ResourceLoader& = delete; + ResourceLoader(ResourceLoader&&) = delete; + auto operator=(ResourceLoader&&) -> ResourceLoader& = delete; + private: ResourceLoader() = default; ~ResourceLoader() = default; - // Disable copy/move - ResourceLoader(const ResourceLoader&) = delete; - ResourceLoader& operator=(const ResourceLoader&) = delete; - ResourceLoader(ResourceLoader&&) = delete; - ResourceLoader& operator=(ResourceLoader&&) = delete; - // Load from filesystem static auto loadFromFilesystem(const std::string& filepath) -> std::vector;