mirror of
https://github.com/esphome/esphome.git
synced 2026-10-04 10:09:13 +00:00
Name the raw string delimiter group and pin the lint invariants in tests
This commit is contained in:
+4
-2
@@ -979,7 +979,8 @@ LOG_CALL_START_RE = re.compile(r"ESP_LOG\w+\s*\(")
|
|||||||
# like 1'000'000 cannot open one.
|
# like 1'000'000 cannot open one.
|
||||||
CPP_COMMENT_RE = r"//[^\n]*|/\*.*?\*/"
|
CPP_COMMENT_RE = r"//[^\n]*|/\*.*?\*/"
|
||||||
CPP_SKIP_RE = (
|
CPP_SKIP_RE = (
|
||||||
CPP_COMMENT_RE + r'|R"([^(\s]*)\(.*?\)\1"|"(?:[^"\\]|\\.)*"|\'(?:[^\'\\\n]|\\.)\''
|
CPP_COMMENT_RE
|
||||||
|
+ r'|R"(?P<raw_delim>[^(\s]*)\(.*?\)(?P=raw_delim)"|"(?:[^"\\]|\\.)*"|\'(?:[^\'\\\n]|\\.)\''
|
||||||
)
|
)
|
||||||
LOG_CALL_TOKEN_RE = re.compile(CPP_SKIP_RE + r"|[()]", re.DOTALL)
|
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,
|
# 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/esp32*/*",
|
||||||
"esphome/components/bk72xx*/*",
|
"esphome/components/bk72xx*/*",
|
||||||
"esphome/components/ln882h*/*",
|
"esphome/components/ln882h*/*",
|
||||||
|
"esphome/components/ln882x*/*",
|
||||||
"esphome/components/rp2*/*",
|
"esphome/components/rp2*/*",
|
||||||
"esphome/components/zephyr*/*",
|
"esphome/components/zephyr*/*",
|
||||||
"esphome/components/host/*",
|
"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 "
|
"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 "
|
"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"{highlight('LOG_STR_LITERAL(...)')}:\n"
|
||||||
f" Before: {highlight(literal)}\n"
|
f" Before: {highlight(literal)}\n"
|
||||||
f" After: {highlight(f'LOG_STR_LITERAL({literal})')}\n"
|
f" After: {highlight(f'LOG_STR_LITERAL({literal})')}\n"
|
||||||
|
|||||||
@@ -77,13 +77,24 @@ def test_exclusion_list_only_names_components_without_esp8266_tests() -> None:
|
|||||||
if not pattern.startswith("esphome/components/"):
|
if not pattern.startswith("esphome/components/"):
|
||||||
continue
|
continue
|
||||||
prefix = pattern.removeprefix("esphome/components/").split("/")[0]
|
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"
|
test = root / "tests" / "components" / comp.name / "test.esp8266-ard.yaml"
|
||||||
assert not test.exists(), (
|
assert not test.exists(), (
|
||||||
f"{comp.name} builds for ESP8266, drop {pattern!r}"
|
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(
|
@pytest.mark.parametrize(
|
||||||
("content", "expected"),
|
("content", "expected"),
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user