From dcd0f53027e2c19786042518a9643ef8880db51a Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Fri, 30 Jan 2026 02:51:20 -0600 Subject: [PATCH] fix clang-tidy warnings - Add NOLINT for intentional global mutable state - Simplify boolean return in parse_posix_tz - Add USE_TIME_TIMEZONE define for tests - Add NOLINT for Google Test SetUp/TearDown methods --- esphome/components/time/posix_tz.cpp | 7 ++----- tests/components/time/posix_tz_parser.cpp | 5 +++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/esphome/components/time/posix_tz.cpp b/esphome/components/time/posix_tz.cpp index af429c43bf..509643de4e 100644 --- a/esphome/components/time/posix_tz.cpp +++ b/esphome/components/time/posix_tz.cpp @@ -8,6 +8,7 @@ namespace esphome::time { // Global timezone - set once at startup, rarely changes +// NOLINTNEXTLINE(cppcoreguidelines-avoid-non-const-global-variables) - intentional mutable state static ParsedTimezone global_tz_{}; void set_global_tz(const ParsedTimezone &tz) { global_tz_ = tz; } @@ -430,12 +431,8 @@ bool parse_posix_tz(const char *tz_string, ParsedTimezone &result) { return false; } p++; - if (!internal::parse_dst_rule(p, result.dst_end)) { - return false; - } - // has_dst() now returns true since dst_start.type was set by parse_dst_rule - return true; + return internal::parse_dst_rule(p, result.dst_end); } bool epoch_to_local_tm(time_t utc_epoch, const ParsedTimezone &tz, struct tm *out_tm) { diff --git a/tests/components/time/posix_tz_parser.cpp b/tests/components/time/posix_tz_parser.cpp index f4b0e91b9f..2f41b17239 100644 --- a/tests/components/time/posix_tz_parser.cpp +++ b/tests/components/time/posix_tz_parser.cpp @@ -1,6 +1,9 @@ // Tests for the POSIX TZ parser and ESPTime::strptime implementations // These custom parsers avoid pulling in scanf (~9.8KB on ESP32-IDF). +// Enable USE_TIME_TIMEZONE for tests +#define USE_TIME_TIMEZONE + #include #include #include @@ -752,6 +755,7 @@ TEST(PosixTzParser, EpochToLocalDstTransition) { class LibcVerificationTest : public ::testing::TestWithParam> { protected: + // NOLINTNEXTLINE(readability-identifier-naming) - Google Test requires this name void SetUp() override { // Save current TZ const char *current_tz = getenv("TZ"); @@ -759,6 +763,7 @@ class LibcVerificationTest : public ::testing::TestWithParam