Fixed clang-tidy warnings

This commit is contained in:
Bartek Kryza
2023-10-21 18:16:27 +02:00
parent 097beb830f
commit 4f43253c0d
6 changed files with 22 additions and 16 deletions

View File

@@ -481,7 +481,8 @@ struct inheritable_diagram_options {
"generate_condition_statements", false}; "generate_condition_statements", false};
option<std::vector<std::string>> participants_order{"participants_order"}; option<std::vector<std::string>> participants_order{"participants_order"};
option<bool> generate_message_comments{"generate_message_comments", false}; option<bool> generate_message_comments{"generate_message_comments", false};
option<unsigned> message_comment_width{"message_comment_width", 25}; option<unsigned> message_comment_width{
"message_comment_width", clanguml::util::kDefaultMessageCommentWidth};
option<bool> debug_mode{"debug_mode", false}; option<bool> debug_mode{"debug_mode", false};
option<bool> generate_metadata{"generate_metadata", true}; option<bool> generate_metadata{"generate_metadata", true};

View File

@@ -110,8 +110,8 @@ void generator::generate_call(const message &m, nlohmann::json &parent) const
msg["from"]["activity_id"] = std::to_string(from.value().id()); msg["from"]["activity_id"] = std::to_string(from.value().id());
msg["to"]["activity_id"] = std::to_string(to.value().id()); msg["to"]["activity_id"] = std::to_string(to.value().id());
msg["to"]["activity_name"] = to.value().full_name(false); msg["to"]["activity_name"] = to.value().full_name(false);
if (m.comment()) if (const auto &cmt = m.comment(); cmt.has_value())
msg["comment"] = m.comment().value(); msg["comment"] = cmt.value();
if (from.value().type_name() == "method") { if (from.value().type_name() == "method") {
const auto &class_participant = const auto &class_participant =

View File

@@ -80,17 +80,19 @@ void generator::generate_message_comment(
if (comment_generated_from_note_decorators) if (comment_generated_from_note_decorators)
return; return;
if (!config().generate_message_comments() || !m.comment()) if (auto &cmt = m.comment();
return; config().generate_message_comments() && cmt.has_value()) {
ostr << indent(1) << "note over " << generate_alias(from.value()) << ": "; ostr << indent(1) << "note over " << generate_alias(from.value())
<< ": ";
auto formatted_message = util::format_message_comment( auto formatted_message = util::format_message_comment(
m.comment().value(), config().message_comment_width()); cmt.value(), config().message_comment_width());
util::replace_all(formatted_message, "\n", "<br/>"); util::replace_all(formatted_message, "\n", "<br/>");
ostr << formatted_message << '\n'; ostr << formatted_message << '\n';
}
} }
void generator::generate_call(const message &m, std::ostream &ostr) const void generator::generate_call(const message &m, std::ostream &ostr) const

View File

@@ -512,7 +512,7 @@ private:
std::optional<std::string> get_expression_comment( std::optional<std::string> get_expression_comment(
const clang::SourceManager &sm, const clang::ASTContext &context, const clang::SourceManager &sm, const clang::ASTContext &context,
const int64_t caller_id, const clang::Stmt *stmt); int64_t caller_id, const clang::Stmt *stmt);
// Reference to the output diagram model // Reference to the output diagram model
clanguml::sequence_diagram::model::diagram &diagram_; clanguml::sequence_diagram::model::diagram &diagram_;

View File

@@ -382,19 +382,19 @@ std::string format_message_comment(const std::string &comment, unsigned width)
return result; return result;
unsigned current_line_length{0}; unsigned current_line_length{0};
for (auto it = tokens.begin(); it != tokens.end(); it++) { for (const auto &token : tokens) {
if (current_line_length < width) { if (current_line_length < width) {
result += *it; result += token;
result += ' '; result += ' ';
} }
else { else {
result.back() = '\n'; result.back() = '\n';
current_line_length = 0; current_line_length = 0;
result += *it; result += token;
result += ' '; result += ' ';
} }
current_line_length += it->size() + 1; current_line_length += token.size() + 1;
} }
result.pop_back(); result.pop_back();

View File

@@ -57,6 +57,8 @@ namespace clanguml::util {
#define FILENAME_ \ #define FILENAME_ \
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
constexpr unsigned kDefaultMessageCommentWidth{25U};
/** /**
* @brief Left trim a string * @brief Left trim a string
* *
@@ -426,6 +428,7 @@ std::string path_to_url(const std::filesystem::path &p);
std::filesystem::path ensure_path_is_absolute(const std::filesystem::path &p, std::filesystem::path ensure_path_is_absolute(const std::filesystem::path &p,
const std::filesystem::path &root = std::filesystem::current_path()); const std::filesystem::path &root = std::filesystem::current_path());
std::string format_message_comment(const std::string &c, unsigned width = 25); std::string format_message_comment(
const std::string &c, unsigned width = kDefaultMessageCommentWidth);
} // namespace clanguml::util } // namespace clanguml::util