mirror of
https://github.com/esphome/esphome.git
synced 2026-10-14 02:02:51 +00:00
[ci] Catch out-of-class member log tags and keep midea's in flash (#20674)
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
namespace esphome::ble_client {
|
||||
|
||||
const char *const Automation::TAG = "ble_client.automation";
|
||||
const char *const Automation::TAG = "ble_client.automation"; // NOLINT: ble_client never builds for ESP8266
|
||||
|
||||
} // namespace esphome::ble_client
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace esphome::midea::ac {
|
||||
|
||||
const char *const Constants::TAG = "midea";
|
||||
const char Constants::TAG[] PROGMEM = "midea";
|
||||
const char *const Constants::FREEZE_PROTECTION = "Freeze Protection";
|
||||
const char *const Constants::SILENT = "Silent";
|
||||
const char *const Constants::TURBO = "Turbo";
|
||||
|
||||
@@ -17,7 +17,7 @@ using MideaPreset = dudanov::midea::ac::Preset;
|
||||
|
||||
class Constants {
|
||||
public:
|
||||
static const char *const TAG;
|
||||
static const char TAG[]; // PROGMEM, like ESPHOME_LOG_TAG
|
||||
static const char *const FREEZE_PROTECTION;
|
||||
static const char *const SILENT;
|
||||
static const char *const TURBO;
|
||||
|
||||
+5
-3
@@ -1274,7 +1274,7 @@ 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*(?:(?:static|constexpr|inline)\s+)*(?:const\s+)?char\s*(?:\*\s*(?:const\s+)?(?:\w+::)*TAG|\s(?:const\s+)?(?:\w+::)*TAG\s*\[\w*\])"
|
||||
r"\s*(?:=\s*\{?|[{(])\s*\"" + CPP_RE_EOL,
|
||||
prefilter="TAG",
|
||||
include=LOG_TAG_INCLUDE,
|
||||
@@ -1285,6 +1285,8 @@ def lint_log_tag_macro(fname, match):
|
||||
f"ESP8266.\n"
|
||||
f" Before: {highlight('static const char *const TAG = "name";')}\n"
|
||||
f" After: {highlight('ESPHOME_LOG_TAG(TAG, "name");')}\n"
|
||||
f"A class member tag cannot use the macro; declare {highlight('static const char TAG[];')} in the class "
|
||||
f"and define {highlight('const char Foo::TAG[] PROGMEM = "name";')} in the .cpp.\n"
|
||||
f"Never pass such a TAG to set_timeout/set_interval names or string functions.\n"
|
||||
f"(If strictly necessary, add `// NOLINT` to the end of the line)"
|
||||
)
|
||||
@@ -1292,8 +1294,8 @@ def lint_log_tag_macro(fname, match):
|
||||
|
||||
@lint_re_check(
|
||||
r"(?:\b(?:set_timeout|set_interval|set_retry|cancel_timeout|cancel_interval|cancel_retry|defer)"
|
||||
r"|\b(?:strcmp|strncmp|strcasecmp|strlen|strcpy|strncpy)|std::string)\s*\((?:(?:[^();]|\([^()]*\))*,)?\s*TAG\b"
|
||||
r"|\bstd::string\s+\w+\s*[={(]\s*TAG\b",
|
||||
r"|\b(?:strcmp|strncmp|strcasecmp|strlen|strcpy|strncpy)|std::string)\s*\((?:(?:[^();]|\([^()]*\))*,)?\s*(?:\w+::)*TAG\b"
|
||||
r"|\bstd::string\s+\w+\s*[={(]\s*(?:\w+::)*TAG\b",
|
||||
mask=True,
|
||||
prefilter="TAG",
|
||||
include=LOG_TAG_INCLUDE,
|
||||
|
||||
@@ -401,6 +401,8 @@ def test_ternary_error_message_names_the_literal() -> None:
|
||||
'static const char TAG[8] = "x";',
|
||||
' static const char *const TAG = "x";',
|
||||
'constexpr static const char *const TAG = "x";',
|
||||
'const char *const Constants::TAG = "x";',
|
||||
'const char Constants::TAG[] = "x";',
|
||||
],
|
||||
)
|
||||
def test_log_tag_macro_flags_plain_tags(line: str) -> None:
|
||||
@@ -413,6 +415,7 @@ def test_log_tag_macro_flags_plain_tags(line: str) -> None:
|
||||
'ESPHOME_LOG_TAG(TAG, "x");',
|
||||
'static const char *const NAME = "x";',
|
||||
'static const char *const TAG = "x"; // NOLINT',
|
||||
'const char Constants::TAG[] PROGMEM = "x";',
|
||||
],
|
||||
)
|
||||
def test_log_tag_macro_ignores_macro_and_other_names(line: str) -> None:
|
||||
@@ -452,6 +455,8 @@ def test_log_tag_lints_cover_headers_and_core(fname: str, covered: bool) -> None
|
||||
"std::string(TAG);",
|
||||
"std::string name = TAG;",
|
||||
"std::string name{TAG};",
|
||||
"strlen(Constants::TAG);",
|
||||
"this->set_timeout(Constants::TAG, 100, cb);",
|
||||
],
|
||||
)
|
||||
def test_log_tag_as_string_flags_string_uses(line: str) -> None:
|
||||
|
||||
Reference in New Issue
Block a user