diff --git a/CMakeLists.txt b/CMakeLists.txt index 65688c96..3cf9d109 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -508,6 +508,7 @@ if(RUN_CLANG_TIDY) set(CLANG_TIDY_LIB_CHECKS ${CLANG_TIDY_COMMON_CHECKS} "cppcoreguidelines-avoid-goto" + "cppcoreguidelines-avoid-magic-numbers" "cppcoreguidelines-non-private-member-variables-in-classes") # Skip some checks for tests because they're not worth the noise (e.g. GTest diff --git a/src/api/game/game.cpp b/src/api/game/game.cpp index 982b3c0f..455c408b 100644 --- a/src/api/game/game.cpp +++ b/src/api/game/game.cpp @@ -111,8 +111,10 @@ void Game::LoadPlugins(const std::vector& plugins, uintmax_t fileSize = Plugin::GetFileSize(DataPath() / u8path(plugin)); // Trim .ghost extension if present. - if (boost::iends_with(plugin, ".ghost")) - sizeMap.emplace(fileSize, plugin.substr(0, plugin.length() - 6)); + if (boost::iends_with(plugin, GHOST_FILE_EXTENSION)) + sizeMap.emplace( + fileSize, + plugin.substr(0, plugin.length() - GHOST_FILE_EXTENSION_LENGTH)); else sizeMap.emplace(fileSize, plugin); } diff --git a/src/api/helpers/text.cpp b/src/api/helpers/text.cpp index a76800eb..792d3e18 100644 --- a/src/api/helpers/text.cpp +++ b/src/api/helpers/text.cpp @@ -81,11 +81,16 @@ std::string EscapeMarkdownASCIIPunctuation(const std::string& text) { std::vector ExtractBashTags(const std::string& description) { std::vector tags; + static constexpr const char* BASH_TAGS_OPENER = "{{BASH:"; + static constexpr std::size_t BASH_TAGS_OPENER_LENGTH = + std::char_traits::length(BASH_TAGS_OPENER); + size_t startPos = description.find("{{BASH:"); - if (startPos == std::string::npos || startPos + 7 >= description.length()) { + if (startPos == std::string::npos || + startPos + BASH_TAGS_OPENER_LENGTH >= description.length()) { return tags; } - startPos += 7; + startPos += BASH_TAGS_OPENER_LENGTH; size_t endPos = description.find("}}", startPos); if (endPos == std::string::npos) { diff --git a/src/api/helpers/text.h b/src/api/helpers/text.h index 5db702f3..d8c1a0b9 100644 --- a/src/api/helpers/text.h +++ b/src/api/helpers/text.h @@ -32,6 +32,10 @@ #include "loot/metadata/tag.h" namespace loot { +static constexpr const char* GHOST_FILE_EXTENSION = ".ghost"; +static constexpr std::size_t GHOST_FILE_EXTENSION_LENGTH = + std::char_traits::length(GHOST_FILE_EXTENSION); + std::string EscapeMarkdownASCIIPunctuation(const std::string& text); std::vector ExtractBashTags(const std::string& description); diff --git a/src/api/metadata/plugin_metadata.cpp b/src/api/metadata/plugin_metadata.cpp index 43925752..1fa705bb 100644 --- a/src/api/metadata/plugin_metadata.cpp +++ b/src/api/metadata/plugin_metadata.cpp @@ -45,8 +45,8 @@ PluginMetadata::PluginMetadata() {} PluginMetadata::PluginMetadata(const std::string& n) : name_(n) { // If the name passed ends in '.ghost', that should be trimmed. - if (boost::iends_with(name_, ".ghost")) { - name_ = name_.substr(0, name_.length() - 6); + if (boost::iends_with(name_, GHOST_FILE_EXTENSION)) { + name_ = name_.substr(0, name_.length() - GHOST_FILE_EXTENSION_LENGTH); } if (IsRegexPlugin()) { diff --git a/src/api/plugin.cpp b/src/api/plugin.cpp index 650c4112..46c8b8c3 100644 --- a/src/api/plugin.cpp +++ b/src/api/plugin.cpp @@ -51,7 +51,7 @@ Plugin::Plugin(const GameType gameType, try { // In case the plugin is ghosted. if (!std::filesystem::exists(pluginPath)) { - pluginPath += ".ghost"; + pluginPath += GHOST_FILE_EXTENSION; } Load(pluginPath, gameType, headerOnly); @@ -240,7 +240,7 @@ bool Plugin::IsValid(const GameType gameType, if (returnCode != ESP_OK || !isValid) { // Try adding .ghost extension. - auto ghostedFilename = pluginPath.u8string() + ".ghost"; + auto ghostedFilename = pluginPath.u8string() + GHOST_FILE_EXTENSION; returnCode = esp_plugin_is_valid( GetEspluginGameId(gameType), ghostedFilename.c_str(), true, &isValid); } @@ -261,7 +261,7 @@ bool Plugin::IsValid(const GameType gameType, uintmax_t Plugin::GetFileSize(std::filesystem::path pluginPath) { if (!std::filesystem::exists(pluginPath)) - pluginPath += ".ghost"; + pluginPath += GHOST_FILE_EXTENSION; return std::filesystem::file_size(pluginPath); } @@ -423,8 +423,9 @@ unsigned int Plugin::GetEspluginGameId(GameType gameType) { } bool hasPluginFileExtension(std::string filename, GameType gameType) { - if (boost::iends_with(filename, ".ghost")) { - filename = filename.substr(0, filename.length() - 6); + if (boost::iends_with(filename, GHOST_FILE_EXTENSION)) { + filename = + filename.substr(0, filename.length() - GHOST_FILE_EXTENSION_LENGTH); } bool isEspOrEsm = boost::iends_with(filename, ".esp") || diff --git a/src/api/sorting/group_sort.cpp b/src/api/sorting/group_sort.cpp index b60aace2..c46be246 100644 --- a/src/api/sorting/group_sort.cpp +++ b/src/api/sorting/group_sort.cpp @@ -251,7 +251,9 @@ std::vector GetGroupsPath(const std::vector& masterlistGroups, std::map weightMap; for (const auto& edge : boost::make_iterator_range(boost::edges(graph))) { if (graph[edge] == EdgeType::userLoadAfter) { - weightMap[edge] = -1000000; // Magnitude is an arbitrarily large number. + // Magnitude is an arbitrarily large number. + static constexpr int USER_LOAD_AFTER_EDGE_WEIGHT = -1000000; + weightMap[edge] = USER_LOAD_AFTER_EDGE_WEIGHT; } else { weightMap[edge] = 1; }