mirror of
https://github.com/esphome/esphome.git
synced 2026-05-28 04:55:48 +08:00
[ci] Add lint check to prevent powf in core and base entity platforms (#14126)
This commit is contained in:
@@ -706,7 +706,7 @@ float gamma_correct(float value, float gamma) {
|
|||||||
if (gamma <= 0.0f)
|
if (gamma <= 0.0f)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
return powf(value, gamma);
|
return powf(value, gamma); // NOLINT - deprecated, removal 2026.9.0
|
||||||
}
|
}
|
||||||
float gamma_uncorrect(float value, float gamma) {
|
float gamma_uncorrect(float value, float gamma) {
|
||||||
if (value <= 0.0f)
|
if (value <= 0.0f)
|
||||||
@@ -714,7 +714,7 @@ float gamma_uncorrect(float value, float gamma) {
|
|||||||
if (gamma <= 0.0f)
|
if (gamma <= 0.0f)
|
||||||
return value;
|
return value;
|
||||||
|
|
||||||
return powf(value, 1 / gamma);
|
return powf(value, 1 / gamma); // NOLINT - deprecated, removal 2026.9.0
|
||||||
}
|
}
|
||||||
|
|
||||||
void rgb_to_hsv(float red, float green, float blue, int &hue, float &saturation, float &value) {
|
void rgb_to_hsv(float red, float green, float blue, int &hue, float &saturation, float &value) {
|
||||||
|
|||||||
@@ -512,8 +512,8 @@ template<size_t STACK_SIZE, typename T = uint8_t> class SmallBufferWithHeapFallb
|
|||||||
///@{
|
///@{
|
||||||
|
|
||||||
/// Compute 10^exp using iterative multiplication/division.
|
/// Compute 10^exp using iterative multiplication/division.
|
||||||
/// Avoids pulling in powf/__ieee754_powf (~2.3KB flash) for small integer exponents.
|
/// Avoids pulling in powf/__ieee754_powf (~2.3KB flash) for small integer exponents. // NOLINT
|
||||||
/// Matches powf(10, exp) for the int8_t exponent range used by sensor accuracy_decimals.
|
/// Matches powf(10, exp) for the int8_t exponent range used by sensor accuracy_decimals. // NOLINT
|
||||||
inline float pow10_int(int8_t exp) {
|
inline float pow10_int(int8_t exp) {
|
||||||
float result = 1.0f;
|
float result = 1.0f;
|
||||||
if (exp >= 0) {
|
if (exp >= 0) {
|
||||||
|
|||||||
@@ -841,6 +841,54 @@ def lint_no_scanf(fname, match):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# Base entity platforms - these are linked into most builds and should not
|
||||||
|
# pull in powf/__ieee754_powf (~2.3KB flash).
|
||||||
|
BASE_ENTITY_PLATFORMS = [
|
||||||
|
"alarm_control_panel",
|
||||||
|
"binary_sensor",
|
||||||
|
"button",
|
||||||
|
"climate",
|
||||||
|
"cover",
|
||||||
|
"datetime",
|
||||||
|
"event",
|
||||||
|
"fan",
|
||||||
|
"light",
|
||||||
|
"lock",
|
||||||
|
"media_player",
|
||||||
|
"number",
|
||||||
|
"select",
|
||||||
|
"sensor",
|
||||||
|
"switch",
|
||||||
|
"text",
|
||||||
|
"text_sensor",
|
||||||
|
"update",
|
||||||
|
"valve",
|
||||||
|
"water_heater",
|
||||||
|
]
|
||||||
|
|
||||||
|
# Directories protected from powf: core + all base entity platforms
|
||||||
|
POWF_PROTECTED_DIRS = ["esphome/core"] + [
|
||||||
|
f"esphome/components/{p}" for p in BASE_ENTITY_PLATFORMS
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@lint_re_check(
|
||||||
|
r"[^\w]powf\s*\(" + CPP_RE_EOL,
|
||||||
|
include=[
|
||||||
|
f"{d}/*.{ext}" for d in POWF_PROTECTED_DIRS for ext in ["h", "cpp", "tcc"]
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def lint_no_powf_in_core(fname, match):
|
||||||
|
return (
|
||||||
|
f"{highlight('powf()')} pulls in __ieee754_powf (~2.3KB flash) and is not allowed in "
|
||||||
|
f"core or base entity platform code. These files are linked into every build.\n"
|
||||||
|
f"Please use alternatives:\n"
|
||||||
|
f" - {highlight('pow10_int(exp)')} for integer powers of 10 (from helpers.h)\n"
|
||||||
|
f" - Precomputed lookup tables for gamma/non-integer exponents\n"
|
||||||
|
f"(If powf is strictly necessary, add `// NOLINT` to the line)"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
LOG_MULTILINE_RE = re.compile(r"ESP_LOG\w+\s*\(.*?;", re.DOTALL)
|
LOG_MULTILINE_RE = re.compile(r"ESP_LOG\w+\s*\(.*?;", re.DOTALL)
|
||||||
LOG_BAD_CONTINUATION_RE = re.compile(r'\\n(?:[^ \\"\r\n\t]|"\s*\n\s*"[^ \\])')
|
LOG_BAD_CONTINUATION_RE = re.compile(r'\\n(?:[^ \\"\r\n\t]|"\s*\n\s*"[^ \\])')
|
||||||
LOG_PERCENT_S_CONTINUATION_RE = re.compile(r'\\n(?:%s|"\s*\n\s*"%s)')
|
LOG_PERCENT_S_CONTINUATION_RE = re.compile(r'\\n(?:%s|"\s*\n\s*"%s)')
|
||||||
|
|||||||
Reference in New Issue
Block a user