diff --git a/script/ci-custom.py b/script/ci-custom.py index e3d826cb38..1e9ba62b5f 100755 --- a/script/ci-custom.py +++ b/script/ci-custom.py @@ -979,7 +979,8 @@ LOG_CALL_START_RE = re.compile(r"ESP_LOG\w+\s*\(") # like 1'000'000 cannot open one. CPP_COMMENT_RE = r"//[^\n]*|/\*.*?\*/" CPP_SKIP_RE = ( - CPP_COMMENT_RE + r'|R"([^(\s]*)\(.*?\)\1"|"(?:[^"\\]|\\.)*"|\'(?:[^\'\\\n]|\\.)\'' + CPP_COMMENT_RE + + r'|R"(?P[^(\s]*)\(.*?\)(?P=raw_delim)"|"(?:[^"\\]|\\.)*"|\'(?:[^\'\\\n]|\\.)\'' ) LOG_CALL_TOKEN_RE = re.compile(CPP_SKIP_RE + r"|[()]", re.DOTALL) # The last alternative matches a ? or : followed (after spaces or comments) by an opening quote, @@ -1084,6 +1085,7 @@ LOG_LITERAL_LINT_EXCLUDE = [ "esphome/components/esp32*/*", "esphome/components/bk72xx*/*", "esphome/components/ln882h*/*", + "esphome/components/ln882x*/*", "esphome/components/rp2*/*", "esphome/components/zephyr*/*", "esphome/components/host/*", @@ -1128,7 +1130,7 @@ def lint_log_no_bare_literal_ternary( ( "String literal used as a ternary branch in a log call. On ESP8266 the " "log macro moves the format string to flash, but bare literal arguments " - "stay in RAM. Wrap each branch in " + "stay in RAM. Wrap each branch passed straight to the log call in " f"{highlight('LOG_STR_LITERAL(...)')}:\n" f" Before: {highlight(literal)}\n" f" After: {highlight(f'LOG_STR_LITERAL({literal})')}\n" diff --git a/tests/script/test_ci_custom.py b/tests/script/test_ci_custom.py index 10baaf37cb..352ef00d5f 100644 --- a/tests/script/test_ci_custom.py +++ b/tests/script/test_ci_custom.py @@ -77,13 +77,24 @@ def test_exclusion_list_only_names_components_without_esp8266_tests() -> None: if not pattern.startswith("esphome/components/"): continue prefix = pattern.removeprefix("esphome/components/").split("/")[0] - for comp in (root / "esphome" / "components").glob(prefix): + comps = list((root / "esphome" / "components").glob(prefix)) + assert comps, f"{pattern!r} matches no component" + for comp in comps: test = root / "tests" / "components" / comp.name / "test.esp8266-ard.yaml" assert not test.exists(), ( f"{comp.name} builds for ESP8266, drop {pattern!r}" ) +def test_unbalanced_calls_are_reported_by_a_check_that_sees_every_file() -> None: + # lint_log_no_bare_literal_ternary skips unbalanced calls and relies on this + checks = {c["func"].__name__: c for c in ci_custom.LINT_CONTENT_CHECKS} + continuation = checks["lint_log_multiline_continuation"] + ternary = checks["lint_log_no_bare_literal_ternary"] + assert continuation["exclude"] == [] + assert continuation["include"] == ternary["include"] + + @pytest.mark.parametrize( ("content", "expected"), [