[core] Catch heap allocating helper calls with explicit template arguments (#20391)

This commit is contained in:
J. Nick Koston
2026-10-10 02:00:41 +00:00
committed by GitHub
parent 41cc96bbb8
commit 0ae24f7536
3 changed files with 33 additions and 10 deletions
+22
View File
@@ -444,6 +444,28 @@ def test_log_tag_as_string_ignores_logging(line: str) -> None:
assert not ci_custom.lint_log_tag_as_string("test.cpp", line + "\n")
@pytest.mark.parametrize(
("content", "flagged"),
[
("auto s = format_hex_pretty(data, len);\n", True),
# Explicit template arguments must not hide the call
("auto s = format_hex_pretty<uint32_t>(v, '\\0', false);\n", True),
("auto s = format_hex<std::array<uint8_t, 4>>(arr);\n", True),
(
"auto s = format_hex<std::conditional_t<true, std::make_unsigned_t<int>, uint64_t>>(v);\n",
True,
),
("auto s = format_hex < 3;\n", False),
("format_hex_pretty_to(buf, sizeof(buf), data, len);\n", False),
],
)
def test_heap_allocating_helpers_detection(content: str, flagged: bool) -> None:
errs = ci_custom.lint_no_heap_allocating_helpers(
Path("esphome/components/x/x.cpp"), content
)
assert bool(errs) is flagged
# --- rule: every component __init__.py defines DOMAIN as its own name ---