mirror of
https://github.com/esphome/esphome.git
synced 2026-10-11 13:54:12 +00:00
[core] Catch heap allocating helper calls with explicit template arguments (#20391)
This commit is contained in:
@@ -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 ---
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user