From e6d783ea202d256e85b416afc3c6f74b8592436e Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 24 Mar 2023 10:41:59 +0000 Subject: [PATCH] Fix a few clang-tidy warnings --- src/cmake_generator.cpp | 16 +++++++--------- src/project_parser.cpp | 6 +++--- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/cmake_generator.cpp b/src/cmake_generator.cpp index f11d0c2..f99244c 100644 --- a/src/cmake_generator.cpp +++ b/src/cmake_generator.cpp @@ -1,12 +1,10 @@ #include "cmake_generator.hpp" -#include "error.hpp" #include "literals.hpp" #include #include "fs.hpp" #include "project_parser.hpp" #include -#include #include #include #include @@ -43,7 +41,7 @@ static tsl::ordered_map> known_languages = {"Swift", {".swift"}}, }; -static std::string format(const char *format, tsl::ordered_map variables) { +static std::string format(const char *format, const tsl::ordered_map &variables) { std::string s = format; for (const auto &itr : variables) { size_t start_pos = 0; @@ -249,7 +247,7 @@ void generate_project(const std::string &type) { struct CommandEndl { std::stringstream &ss; - CommandEndl(std::stringstream &ss) : ss(ss) { + explicit CommandEndl(std::stringstream &ss) : ss(ss) { } void endl() { ss << '\n'; @@ -258,7 +256,7 @@ struct CommandEndl { struct RawArg { RawArg() = default; - RawArg(std::string arg) : arg(std::move(arg)) { + explicit RawArg(std::string arg) : arg(std::move(arg)) { } std::string arg; @@ -293,7 +291,7 @@ struct Command { // https://cmake.org/cmake/help/latest/manual/cmake-language.7.html#unquoted-argument // NOTE: Normally '/' does not require quoting according to the documentation but this has been the case here // previously, so for backwards compatibility its still here. - if (str.find_first_of("()#\"\\'> |/;") == str.npos) + if (str.find_first_of("()#\"\\'> |/;") == std::string::npos) return str; std::string result; result += "\""; @@ -442,10 +440,10 @@ static std::string tolf(const std::string &str) { } } return result; -}; +} struct Generator { - Generator(const parser::Project &project, const fs::path &path) : project(project), path(path) { + Generator(const parser::Project &project, fs::path path) : project(project), path(std::move(path)) { } Generator(const Generator &) = delete; @@ -893,7 +891,7 @@ void generate_cmake(const char *path, const parser::Project *parent_project) { gen.conditional_includes(content.include_before); gen.conditional_cmake(content.cmake_before); - std::string version_info = ""; + std::string version_info; if (content.arguments.contains("GIT_TAG")) { version_info = " (" + content.arguments.at("GIT_TAG") + ")"; } else if (content.arguments.contains("SVN_REVISION")) { diff --git a/src/project_parser.cpp b/src/project_parser.cpp index 3e722cb..59f4bf7 100644 --- a/src/project_parser.cpp +++ b/src/project_parser.cpp @@ -36,7 +36,7 @@ static std::string format_key_message(const std::string &message, const toml::ke auto loc = value.location(); auto line_number_str = std::to_string(loc.line()); auto line_width = line_number_str.length(); - auto line_str = loc.line_str(); + const auto& line_str = loc.line_str(); std::ostringstream oss; oss << message << "\n"; @@ -73,7 +73,7 @@ class TomlChecker { public: TomlChecker(const TomlBasicValue &v, const toml::key &ky) : m_v(toml::find(v, ky)) { } - TomlChecker(const TomlBasicValue &v) : m_v(v) { + explicit TomlChecker(const TomlBasicValue &v) : m_v(v) { } TomlChecker(const TomlChecker &) = delete; TomlChecker(TomlChecker &&) = delete; @@ -175,7 +175,7 @@ class TomlCheckerRoot { bool m_checked = false; public: - TomlCheckerRoot(const TomlBasicValue &root) : m_root(root) { + explicit TomlCheckerRoot(const TomlBasicValue &root) : m_root(root) { } TomlCheckerRoot(const TomlCheckerRoot &) = delete; TomlCheckerRoot(TomlCheckerRoot &&) = delete;