clang-tidy

This commit is contained in:
Tomasz Duda 2024-08-09 20:00:41 +02:00
parent 355ff1cf4d
commit 0778cc3c72
10 changed files with 70 additions and 19 deletions

View file

@ -47,7 +47,7 @@ class HaierClimateBase : public esphome::Component,
void set_supported_presets(const std::set<esphome::climate::ClimatePreset> &presets);
bool valid_connection() const { return this->protocol_phase_ >= ProtocolPhases::IDLE; };
size_t available() noexcept override { return esphome::uart::UARTDevice::available(); };
size_t read_array(uint8_t *data, size_t len) noexcept override {
size_t read_array(uint8_t *data, size_t len) noexcept override { // NOLINT(readability-non-const-parameter)
return esphome::uart::UARTDevice::read_array(data, len) ? len : 0;
};
void write_array(const uint8_t *data, size_t len) noexcept override {

View file

@ -18,7 +18,7 @@ class LVLight : public light::LightOutput {
float red, green, blue;
state->current_values_as_rgb(&red, &green, &blue, false);
auto color = lv_color_make(red * 255, green * 255, blue * 255);
if (this->obj_ != nullptr) {
if (this->obj_ != nullptr) { // NOLINT(bugprone-branch-clone)
this->set_value_(color);
} else {
this->initial_value_ = color;

View file

@ -1,8 +1,6 @@
from esphome.core import CORE
import esphome.codegen as cg
import esphome.config_validation as cv
from esphome.components.esp32 import add_idf_sdkconfig_option
import esphome.config_validation as cv
from esphome.const import (
CONF_ENABLE_IPV6,
CONF_MIN_IPV6_ADDR_COUNT,
@ -10,6 +8,7 @@ from esphome.const import (
PLATFORM_ESP8266,
PLATFORM_RP2040,
)
from esphome.core import CORE
CODEOWNERS = ["@esphome/core"]
AUTO_LOAD = ["mdns"]
@ -33,6 +32,7 @@ CONFIG_SCHEMA = cv.Schema(
async def to_code(config):
cg.add_define("USE_NETWORK")
if (enable_ipv6 := config.get(CONF_ENABLE_IPV6, None)) is not None:
cg.add_define("USE_NETWORK_IPV6", enable_ipv6)
if enable_ipv6:
@ -42,11 +42,10 @@ async def to_code(config):
if CORE.using_esp_idf:
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6", enable_ipv6)
add_idf_sdkconfig_option("CONFIG_LWIP_IPV6_AUTOCONFIG", enable_ipv6)
else:
if enable_ipv6:
cg.add_build_flag("-DCONFIG_LWIP_IPV6")
cg.add_build_flag("-DCONFIG_LWIP_IPV6_AUTOCONFIG")
if CORE.is_rp2040:
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_ENABLE_IPV6")
if CORE.is_esp8266:
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY")
elif enable_ipv6:
cg.add_build_flag("-DCONFIG_LWIP_IPV6")
cg.add_build_flag("-DCONFIG_LWIP_IPV6_AUTOCONFIG")
if CORE.is_rp2040:
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_ENABLE_IPV6")
if CORE.is_esp8266:
cg.add_build_flag("-DPIO_FRAMEWORK_ARDUINO_LWIP2_IPV6_LOW_MEMORY")

View file

@ -1,4 +1,6 @@
#pragma once
#include "esphome/core/defines.h"
#ifdef USE_NETWORK
#include <cstdint>
#include <string>
#include <cstdio>
@ -140,3 +142,4 @@ using IPAddresses = std::array<IPAddress, 5>;
} // namespace network
} // namespace esphome
#endif

View file

@ -1,5 +1,6 @@
#pragma once
#include "esphome/core/defines.h"
#ifdef USE_NETWORK
#include <string>
#include "ip_address.h"
@ -16,3 +17,4 @@ IPAddresses get_ip_addresses();
} // namespace network
} // namespace esphome
#endif

View file

@ -79,7 +79,7 @@ class PartitionLightOutput : public light::AddressableLight {
int32_t seg_off = index - seg.get_dst_offset();
// offset within the src
int32_t src_off;
if (seg.is_reversed()) {
if (seg.is_reversed()) { // NOLINT(bugprone-branch-clone)
src_off = seg.get_src_offset() + seg.get_size() - seg_off - 1;
} else {
src_off = seg.get_src_offset() + seg_off;

View file

@ -1,9 +1,10 @@
#pragma once
#include "esphome/core/defines.h"
#ifdef USE_WIFI
#include "esphome/components/network/ip_address.h"
#include "esphome/core/automation.h"
#include "esphome/core/component.h"
#include "esphome/core/defines.h"
#include "esphome/core/helpers.h"
#include <string>
@ -442,3 +443,4 @@ template<typename... Ts> class WiFiDisableAction : public Action<Ts...> {
} // namespace wifi
} // namespace esphome
#endif

View file

@ -50,7 +50,6 @@
#define USE_LVGL_ROTARY_ENCODER
#define USE_MDNS
#define USE_MEDIA_PLAYER
#define USE_MQTT
#define USE_NEXTION_TFT_UPLOAD
#define USE_NUMBER
#define USE_ONLINE_IMAGE_PNG_SUPPORT
@ -72,8 +71,14 @@
#define USE_UART_DEBUGGER
#define USE_UPDATE
#define USE_VALVE
// Things which do not work for zephyr
#ifndef USE_ZEPHYR
#define USE_MQTT
#define USE_NETWORK
#define USE_WIFI
#define USE_WIFI_AP
#endif
// Arduino-specific feature flags
#ifdef USE_ARDUINO

View file

@ -236,7 +236,44 @@ def main():
files = split_list(files, args.split_num)[args.split_at - 1]
if args.all_headers and args.split_at in (None, 1):
build_all_include()
triplet = os.path.basename(idedata["cxx_path"])[:-4]
exclude_components = []
if "zephyr" in triplet:
exclude_components = [
"api",
"web_server_base",
"web_server",
"prometheus",
"captive_portal",
"socket",
"voice_assistant",
"homeassistant",
"bluetooth_proxy",
"wake_on_lan",
"esphome",
"e131",
"haier",
"improv_serial",
"lvgl",
"fingerprint_grow",
"md5",
"mlx90393",
"mqtt",
"online_image",
"sgp4x",
"wireguard",
"tuya",
"status",
"nextion",
"mqtt",
"improv_base",
"http_request",
"ota",
"wifi_info",
"wifi_signal",
"bedjet",
]
build_all_include(exclude_components)
files.insert(0, temp_header_file)
tmpdir = None

View file

@ -29,7 +29,7 @@ def print_error_for_file(file, body):
print()
def build_all_include():
def build_all_include(exclude_components):
# Build a cpp file that includes all header files in this repo.
# Otherwise header-only integrations would not be tested by clang-tidy
headers = []
@ -37,6 +37,9 @@ def build_all_include():
filetypes = (".h",)
ext = os.path.splitext(path)[1]
if ext in filetypes:
parts = path.split("/components/")
if len(parts) > 1 and parts[1].split("/")[0] in exclude_components:
continue
path = os.path.relpath(path, root_path)
include_p = path.replace(os.path.sep, "/")
headers.append(f'#include "{include_p}"')