Add cppcoreguidelines-avoid-magic-numbers clang-tidy check

Fix the warnings it emits.
This commit is contained in:
Oliver Hamlet
2022-02-07 20:25:13 +00:00
parent 4393dd0e66
commit 9e0ac81d66
7 changed files with 27 additions and 12 deletions
+1
View File
@@ -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
+4 -2
View File
@@ -111,8 +111,10 @@ void Game::LoadPlugins(const std::vector<std::string>& 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);
}
+7 -2
View File
@@ -81,11 +81,16 @@ std::string EscapeMarkdownASCIIPunctuation(const std::string& text) {
std::vector<Tag> ExtractBashTags(const std::string& description) {
std::vector<Tag> tags;
static constexpr const char* BASH_TAGS_OPENER = "{{BASH:";
static constexpr std::size_t BASH_TAGS_OPENER_LENGTH =
std::char_traits<char>::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) {
+4
View File
@@ -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<char>::length(GHOST_FILE_EXTENSION);
std::string EscapeMarkdownASCIIPunctuation(const std::string& text);
std::vector<Tag> ExtractBashTags(const std::string& description);
+2 -2
View File
@@ -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()) {
+6 -5
View File
@@ -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") ||
+3 -1
View File
@@ -251,7 +251,9 @@ std::vector<Vertex> GetGroupsPath(const std::vector<Group>& masterlistGroups,
std::map<edge_t, int> 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;
}