[ci] Lint log tags in headers and core (#20668)

This commit is contained in:
J. Nick Koston
2026-10-14 12:21:24 +13:00
committed by GitHub
parent f61955baa2
commit 92f6ab8367
5 changed files with 39 additions and 7 deletions
+2 -1
View File
@@ -2,12 +2,13 @@
#include "esphome/components/spi/spi.h"
#include "esphome/components/display/display_buffer.h"
#include "esphome/components/display/display_color_utils.h"
#include "esphome/core/log.h"
#include "ili9xxx_defines.h"
#include "ili9xxx_init.h"
namespace esphome::ili9xxx {
static const char *const TAG = "ili9xxx";
ESPHOME_LOG_TAG(TAG, "ili9xxx");
const size_t ILI9XXX_TRANSFER_BUFFER_SIZE = 126; // ensure this is divisible by 6
enum ILI9XXXColorMode {
+2 -1
View File
@@ -8,12 +8,13 @@
#include "esphome/components/display/display.h"
#include "esphome/components/display/display_buffer.h"
#include "esphome/components/display/display_color_utils.h"
#include "esphome/core/log.h"
#include "esp_lcd_panel_rgb.h"
namespace esphome::qspi_dbi {
constexpr static const char *const TAG = "display.qspi_dbi";
ESPHOME_LOG_TAG(TAG, "display.qspi_dbi");
static const uint8_t SW_RESET_CMD = 0x01;
static const uint8_t SLEEP_OUT = 0x11;
static const uint8_t NORON = 0x13;
+1 -1
View File
@@ -16,7 +16,7 @@
namespace esphome::rpi_dpi_rgb {
constexpr static const char *const TAG = "rpi_dpi_rgb";
ESPHOME_LOG_TAG(TAG, "rpi_dpi_rgb");
class RpiDpiRgb final : public display::Display {
public:
+7 -3
View File
@@ -1269,11 +1269,15 @@ def lint_no_std_nothrow(fname, match):
)
# Every C++ source and header; plain C files cannot use the macro
LOG_TAG_INCLUDE = ["esphome/*.cpp", "esphome/*.h"]
@lint_re_check(
r"^\s*(?:(?:static|constexpr|inline)\s+)*(?:const\s+)?char\s*(?:\*\s*(?:const\s+)?TAG|\s(?:const\s+)?TAG\s*\[\w*\])"
r"\s*(?:=\s*\{?|[{(])\s*\"",
r"\s*(?:=\s*\{?|[{(])\s*\"" + CPP_RE_EOL,
prefilter="TAG",
include=["esphome/components/*.cpp", "esphome/components/**/*.cpp"],
include=LOG_TAG_INCLUDE,
)
def lint_log_tag_macro(fname, match):
return (
@@ -1292,7 +1296,7 @@ def lint_log_tag_macro(fname, match):
r"|\bstd::string\s+\w+\s*[={(]\s*TAG\b",
mask=True,
prefilter="TAG",
include=["esphome/components/*.cpp", "esphome/components/**/*.cpp"],
include=LOG_TAG_INCLUDE,
)
def lint_log_tag_as_string(fname, match):
return (
+27 -1
View File
@@ -400,6 +400,7 @@ def test_ternary_error_message_names_the_literal() -> None:
'static constexpr char TAG[] = {"x"};',
'static const char TAG[8] = "x";',
' static const char *const TAG = "x";',
'constexpr static const char *const TAG = "x";',
],
)
def test_log_tag_macro_flags_plain_tags(line: str) -> None:
@@ -408,12 +409,37 @@ def test_log_tag_macro_flags_plain_tags(line: str) -> None:
@pytest.mark.parametrize(
"line",
['ESPHOME_LOG_TAG(TAG, "x");', 'static const char *const NAME = "x";'],
[
'ESPHOME_LOG_TAG(TAG, "x");',
'static const char *const NAME = "x";',
'static const char *const TAG = "x"; // NOLINT',
],
)
def test_log_tag_macro_ignores_macro_and_other_names(line: str) -> None:
assert not ci_custom.lint_log_tag_macro("test.cpp", line + "\n")
@pytest.mark.parametrize(
("fname", "covered"),
[
("esphome/components/x/x.cpp", True),
("esphome/components/x/x.h", True),
("esphome/components/x/sub/x.h", True),
("esphome/core/wake/wake_host.cpp", True),
("esphome/components/x/x.c", False),
],
)
def test_log_tag_lints_cover_headers_and_core(fname: str, covered: bool) -> None:
for name, line in (
("lint_log_tag_macro", 'static const char *const TAG = "x";\n'),
("lint_log_tag_as_string", "strcmp(TAG, name);\n"),
):
lint = next(
c for c in ci_custom.LINT_CONTENT_CHECKS if c["func"].__name__ == name
)
assert bool(ci_custom.run_check(lint, fname, fname, line)) is covered
@pytest.mark.parametrize(
"line",
[