From 38f6b5ea71158818c6e90c6c43b91dfcec786a1d Mon Sep 17 00:00:00 2001 From: gabime Date: Mon, 3 Jun 2019 22:49:21 +0300 Subject: [PATCH] Keep clang-tidy happy --- .clang-tidy | 2 +- include/spdlog/details/file_helper.h | 4 ++-- include/spdlog/details/os-inl.h | 5 +++-- include/spdlog/details/pattern_formatter-inl.h | 16 +++++++++------- include/spdlog/logger.h | 5 +++-- include/spdlog/sinks/ansicolor_sink.h | 2 +- 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 309c7e94..6c4c87c2 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,4 @@ -Checks: 'modernize-*,modernize-use-override,google-*,-google-runtime-references,misc-*,clang-analyzer-*' +Checks: 'modernize-*,modernize-use-override,google-*,-google-runtime-references,misc-*,clang-analyzer-*,-misc-non-private-member-variables-in-classes' WarningsAsErrors: '' HeaderFilterRegex: 'async.h|async_logger.h|common.h|details|formatter.h|logger.h|sinks|spdlog.h|tweakme.h|version.h' AnalyzeTemporaryDtors: false diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index afacc4c6..70ff03b9 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -16,8 +16,6 @@ namespace details { class file_helper { public: - const int open_tries = 5; - const int open_interval = 10; explicit file_helper() = default; file_helper(const file_helper &) = delete; @@ -49,6 +47,8 @@ public: static std::tuple split_by_extension(const filename_t &fname); private: + const int open_tries = 5; + const int open_interval = 10; std::FILE *fd_{nullptr}; filename_t _filename; }; diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index d6af8048..b7f66f41 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -370,8 +371,8 @@ SPDLOG_INLINE bool is_color_terminal() SPDLOG_NOEXCEPT #ifdef _WIN32 return true; #else - static constexpr const char *Terms[] = { - "ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}; + static constexpr std::arrayTerms = { + "ansi", "color", "console", "cygwin", "gnome", "konsole", "kterm", "linux", "msys", "putty", "rxvt", "screen", "vt100", "xterm"}; const char *env_p = std::getenv("TERM"); if (env_p == nullptr) diff --git a/include/spdlog/details/pattern_formatter-inl.h b/include/spdlog/details/pattern_formatter-inl.h index b798dc0d..e0c1f064 100644 --- a/include/spdlog/details/pattern_formatter-inl.h +++ b/include/spdlog/details/pattern_formatter-inl.h @@ -163,7 +163,7 @@ static int to12h(const tm &t) } // Abbreviated weekday name -static const char *days[]{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; +static std::array days{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; class a_formatter : public flag_formatter { public: @@ -180,7 +180,7 @@ public: }; // Full weekday name -static const char *full_days[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; +static std::array full_days{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; class A_formatter : public flag_formatter { public: @@ -197,7 +197,7 @@ public: }; // Abbreviated month -static const char *months[]{"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}; +static const std::array months {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov", "Dec"}; class b_formatter : public flag_formatter { public: @@ -214,8 +214,9 @@ public: }; // Full month name -static const char *full_months[]{ - "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; +static const std::array full_months { + "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; + class B_formatter : public flag_formatter { public: @@ -575,7 +576,7 @@ public: explicit z_formatter(padding_info padinfo) : flag_formatter(padinfo){} - const std::chrono::seconds cache_refresh = std::chrono::seconds(5); + z_formatter() = default; z_formatter(const z_formatter &) = delete; @@ -617,7 +618,8 @@ private: int get_cached_offset(const log_msg &msg, const std::tm &tm_time) { - if (msg.time - last_update_ >= cache_refresh) + // refresh every 10 seconds + if (msg.time - last_update_ >= std::chrono::seconds(10)) { offset_minutes_ = os::utc_minutes_offset(tm_time); last_update_ = msg.time; diff --git a/include/spdlog/logger.h b/include/spdlog/logger.h index 8ab8aaed..0065bf9f 100644 --- a/include/spdlog/logger.h +++ b/include/spdlog/logger.h @@ -32,9 +32,10 @@ class logger { public: // Empty logger - logger(std::string name) : + explicit logger(std::string name) : name_(std::move(name)), - sinks_(){} + sinks_() + {} // Logger with range on sinks template diff --git a/include/spdlog/sinks/ansicolor_sink.h b/include/spdlog/sinks/ansicolor_sink.h index f940255e..1e068bc0 100644 --- a/include/spdlog/sinks/ansicolor_sink.h +++ b/include/spdlog/sinks/ansicolor_sink.h @@ -29,7 +29,7 @@ class ansicolor_sink final : public sink { public: using mutex_t = typename ConsoleMutex::mutex_t; - ansicolor_sink(color_mode mode = color_mode::automatic); + explicit ansicolor_sink(color_mode mode = color_mode::automatic); ~ansicolor_sink() override = default; ansicolor_sink(const ansicolor_sink &other) = delete;