From cd72a2ed7eff504089adcf5fc8d37c9ddfdaf86c Mon Sep 17 00:00:00 2001 From: Sergey Dudanov Date: Sun, 30 Jul 2023 23:44:56 +0400 Subject: [PATCH] Bump clang-tidy from 11 to 14 (#5160) --- .clang-tidy | 15 +++++++++++++-- .github/workflows/ci.yml | 2 +- esphome/components/logger/logger.cpp | 2 +- .../components/matrix_keypad/matrix_keypad.cpp | 6 ++++-- esphome/components/remote_base/midea_protocol.h | 2 -- esphome/components/ssd1322_spi/ssd1322_spi.cpp | 3 +-- esphome/components/ssd1325_spi/ssd1325_spi.cpp | 3 +-- esphome/components/ssd1327_spi/ssd1327_spi.cpp | 3 +-- esphome/components/ssd1331_spi/ssd1331_spi.cpp | 3 +-- esphome/components/ssd1351_spi/ssd1351_spi.cpp | 3 +-- esphome/components/tlc5947/tlc5947.cpp | 3 +-- .../vbus/binary_sensor/vbus_binary_sensor.cpp | 3 ++- esphome/components/vbus/sensor/vbus_sensor.cpp | 3 ++- .../components/voice_assistant/voice_assistant.h | 1 - .../wifi/wifi_component_esp32_arduino.cpp | 2 +- .../components/wifi/wifi_component_esp_idf.cpp | 2 +- script/clang-tidy | 12 ++++++------ 17 files changed, 37 insertions(+), 31 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index c9b77b5720..946f2950d8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -5,9 +5,12 @@ Checks: >- -altera-*, -android-*, -boost-*, + -bugprone-easily-swappable-parameters, + -bugprone-implicit-widening-of-multiplication-result, -bugprone-narrowing-conversions, -bugprone-signed-char-misuse, -cert-dcl50-cpp, + -cert-err33-c, -cert-err58-cpp, -cert-oop57-cpp, -cert-str34-c, @@ -15,6 +18,7 @@ Checks: >- -clang-analyzer-osx.*, -clang-diagnostic-delete-abstract-non-virtual-dtor, -clang-diagnostic-delete-non-abstract-non-virtual-dtor, + -clang-diagnostic-ignored-optimization-argument, -clang-diagnostic-shadow-field, -clang-diagnostic-unused-const-variable, -clang-diagnostic-unused-parameter, @@ -25,6 +29,7 @@ Checks: >- -cppcoreguidelines-macro-usage, -cppcoreguidelines-narrowing-conversions, -cppcoreguidelines-non-private-member-variables-in-classes, + -cppcoreguidelines-prefer-member-initializer, -cppcoreguidelines-pro-bounds-array-to-pointer-decay, -cppcoreguidelines-pro-bounds-constant-array-index, -cppcoreguidelines-pro-bounds-pointer-arithmetic, @@ -36,6 +41,7 @@ Checks: >- -cppcoreguidelines-pro-type-union-access, -cppcoreguidelines-pro-type-vararg, -cppcoreguidelines-special-member-functions, + -cppcoreguidelines-virtual-class-destructor, -fuchsia-multiple-inheritance, -fuchsia-overloaded-operator, -fuchsia-statically-constructed-objects, @@ -68,6 +74,7 @@ Checks: >- -modernize-use-nodiscard, -mpi-*, -objc-*, + -readability-container-data-pointer, -readability-convert-member-functions-to-static, -readability-else-after-return, -readability-function-cognitive-complexity, @@ -82,8 +89,6 @@ WarningsAsErrors: '*' AnalyzeTemporaryDtors: false FormatStyle: google CheckOptions: - - key: google-readability-braces-around-statements.ShortStatementLines - value: '1' - key: google-readability-function-size.StatementThreshold value: '800' - key: google-runtime-int.TypeSuffix @@ -158,3 +163,9 @@ CheckOptions: value: '' - key: readability-qualified-auto.AddConstToQualified value: 0 + - key: readability-identifier-length.MinimumVariableNameLength + value: 0 + - key: readability-identifier-length.MinimumParameterNameLength + value: 0 + - key: readability-identifier-length.MinimumLoopCounterNameLength + value: 0 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7775a996fc..ba46936952 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -305,7 +305,7 @@ jobs: key: platformio-${{ matrix.pio_cache_key }}-${{ hashFiles('platformio.ini') }} - name: Install clang-tidy - run: sudo apt-get install clang-tidy-11 + run: sudo apt-get install clang-tidy-14 - name: Register problem matchers run: | diff --git a/esphome/components/logger/logger.cpp b/esphome/components/logger/logger.cpp index 8fd39265fd..ca4cc64007 100644 --- a/esphome/components/logger/logger.cpp +++ b/esphome/components/logger/logger.cpp @@ -125,7 +125,7 @@ void HOT Logger::log_message_(int level, const char *tag, int offset) { #elif defined(USE_ESP32_VARIANT_ESP32S3) uart_ == UART_SELECTION_USB_CDC || uart_ == UART_SELECTION_USB_SERIAL_JTAG #else - /* DISABLES CODE */ (false) + /* DISABLES CODE */ (false) // NOLINT #endif ) { puts(msg); diff --git a/esphome/components/matrix_keypad/matrix_keypad.cpp b/esphome/components/matrix_keypad/matrix_keypad.cpp index f4e7bf4d23..4f8962a782 100644 --- a/esphome/components/matrix_keypad/matrix_keypad.cpp +++ b/esphome/components/matrix_keypad/matrix_keypad.cpp @@ -89,11 +89,13 @@ void MatrixKeypad::loop() { void MatrixKeypad::dump_config() { ESP_LOGCONFIG(TAG, "Matrix Keypad:"); ESP_LOGCONFIG(TAG, " Rows:"); - for (auto &pin : this->rows_) + for (auto &pin : this->rows_) { LOG_PIN(" Pin: ", pin); + } ESP_LOGCONFIG(TAG, " Cols:"); - for (auto &pin : this->columns_) + for (auto &pin : this->columns_) { LOG_PIN(" Pin: ", pin); + } } void MatrixKeypad::register_listener(MatrixKeypadListener *listener) { this->listeners_.push_back(listener); } diff --git a/esphome/components/remote_base/midea_protocol.h b/esphome/components/remote_base/midea_protocol.h index a7f5636b06..d81a50241b 100644 --- a/esphome/components/remote_base/midea_protocol.h +++ b/esphome/components/remote_base/midea_protocol.h @@ -22,8 +22,6 @@ class MideaData { MideaData(const std::vector &data) { std::copy_n(data.begin(), std::min(data.size(), this->data_.size()), this->data_.begin()); } - // Default copy constructor - MideaData(const MideaData &) = default; uint8_t *data() { return this->data_.data(); } const uint8_t *data() const { return this->data_.data(); } diff --git a/esphome/components/ssd1322_spi/ssd1322_spi.cpp b/esphome/components/ssd1322_spi/ssd1322_spi.cpp index 50c46c4d02..a841c5606e 100644 --- a/esphome/components/ssd1322_spi/ssd1322_spi.cpp +++ b/esphome/components/ssd1322_spi/ssd1322_spi.cpp @@ -21,8 +21,7 @@ void SPISSD1322::setup() { void SPISSD1322::dump_config() { LOG_DISPLAY("", "SPI SSD1322", this); ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_()); - if (this->cs_) - LOG_PIN(" CS Pin: ", this->cs_); + LOG_PIN(" CS Pin: ", this->cs_); LOG_PIN(" DC Pin: ", this->dc_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_); diff --git a/esphome/components/ssd1325_spi/ssd1325_spi.cpp b/esphome/components/ssd1325_spi/ssd1325_spi.cpp index 98f48b8538..8a95bfeae3 100644 --- a/esphome/components/ssd1325_spi/ssd1325_spi.cpp +++ b/esphome/components/ssd1325_spi/ssd1325_spi.cpp @@ -21,8 +21,7 @@ void SPISSD1325::setup() { void SPISSD1325::dump_config() { LOG_DISPLAY("", "SPI SSD1325", this); ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_()); - if (this->cs_) - LOG_PIN(" CS Pin: ", this->cs_); + LOG_PIN(" CS Pin: ", this->cs_); LOG_PIN(" DC Pin: ", this->dc_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_); diff --git a/esphome/components/ssd1327_spi/ssd1327_spi.cpp b/esphome/components/ssd1327_spi/ssd1327_spi.cpp index 1dd2b73e66..c6ae377119 100644 --- a/esphome/components/ssd1327_spi/ssd1327_spi.cpp +++ b/esphome/components/ssd1327_spi/ssd1327_spi.cpp @@ -21,8 +21,7 @@ void SPISSD1327::setup() { void SPISSD1327::dump_config() { LOG_DISPLAY("", "SPI SSD1327", this); ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_()); - if (this->cs_) - LOG_PIN(" CS Pin: ", this->cs_); + LOG_PIN(" CS Pin: ", this->cs_); LOG_PIN(" DC Pin: ", this->dc_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_); diff --git a/esphome/components/ssd1331_spi/ssd1331_spi.cpp b/esphome/components/ssd1331_spi/ssd1331_spi.cpp index ff42c74b9f..88116f6c00 100644 --- a/esphome/components/ssd1331_spi/ssd1331_spi.cpp +++ b/esphome/components/ssd1331_spi/ssd1331_spi.cpp @@ -20,8 +20,7 @@ void SPISSD1331::setup() { } void SPISSD1331::dump_config() { LOG_DISPLAY("", "SPI SSD1331", this); - if (this->cs_) - LOG_PIN(" CS Pin: ", this->cs_); + LOG_PIN(" CS Pin: ", this->cs_); LOG_PIN(" DC Pin: ", this->dc_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_); diff --git a/esphome/components/ssd1351_spi/ssd1351_spi.cpp b/esphome/components/ssd1351_spi/ssd1351_spi.cpp index 9599c6e644..b71b8f4f88 100644 --- a/esphome/components/ssd1351_spi/ssd1351_spi.cpp +++ b/esphome/components/ssd1351_spi/ssd1351_spi.cpp @@ -21,8 +21,7 @@ void SPISSD1351::setup() { void SPISSD1351::dump_config() { LOG_DISPLAY("", "SPI SSD1351", this); ESP_LOGCONFIG(TAG, " Model: %s", this->model_str_()); - if (this->cs_) - LOG_PIN(" CS Pin: ", this->cs_); + LOG_PIN(" CS Pin: ", this->cs_); LOG_PIN(" DC Pin: ", this->dc_pin_); LOG_PIN(" Reset Pin: ", this->reset_pin_); ESP_LOGCONFIG(TAG, " Initial Brightness: %.2f", this->brightness_); diff --git a/esphome/components/tlc5947/tlc5947.cpp b/esphome/components/tlc5947/tlc5947.cpp index a7e08c8341..8f3f60f087 100644 --- a/esphome/components/tlc5947/tlc5947.cpp +++ b/esphome/components/tlc5947/tlc5947.cpp @@ -27,8 +27,7 @@ void TLC5947::dump_config() { LOG_PIN(" Data Pin: ", this->data_pin_); LOG_PIN(" Clock Pin: ", this->clock_pin_); LOG_PIN(" LAT Pin: ", this->lat_pin_); - if (this->outenable_pin_ != nullptr) - LOG_PIN(" OE Pin: ", this->outenable_pin_); + LOG_PIN(" OE Pin: ", this->outenable_pin_); ESP_LOGCONFIG(TAG, " Number of chips: %u", this->num_chips_); } diff --git a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp index 087d049a57..4ccd149935 100644 --- a/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp +++ b/esphome/components/vbus/binary_sensor/vbus_binary_sensor.cpp @@ -147,8 +147,9 @@ void VBusCustomBSensor::dump_config() { ESP_LOGCONFIG(TAG, " Command: 0x%04x", this->command_); } ESP_LOGCONFIG(TAG, " Binary Sensors:"); - for (VBusCustomSubBSensor *bsensor : this->bsensors_) + for (VBusCustomSubBSensor *bsensor : this->bsensors_) { LOG_BINARY_SENSOR(" ", "-", bsensor); + } } void VBusCustomBSensor::handle_message(std::vector &message) { diff --git a/esphome/components/vbus/sensor/vbus_sensor.cpp b/esphome/components/vbus/sensor/vbus_sensor.cpp index 5b4f57f73d..e81c0486d4 100644 --- a/esphome/components/vbus/sensor/vbus_sensor.cpp +++ b/esphome/components/vbus/sensor/vbus_sensor.cpp @@ -232,8 +232,9 @@ void VBusCustomSensor::dump_config() { ESP_LOGCONFIG(TAG, " Command: 0x%04x", this->command_); } ESP_LOGCONFIG(TAG, " Sensors:"); - for (VBusCustomSubSensor *sensor : this->sensors_) + for (VBusCustomSubSensor *sensor : this->sensors_) { LOG_SENSOR(" ", "-", sensor); + } } void VBusCustomSensor::handle_message(std::vector &message) { diff --git a/esphome/components/voice_assistant/voice_assistant.h b/esphome/components/voice_assistant/voice_assistant.h index e67baaee65..75c17965bc 100644 --- a/esphome/components/voice_assistant/voice_assistant.h +++ b/esphome/components/voice_assistant/voice_assistant.h @@ -6,7 +6,6 @@ #include "esphome/core/automation.h" #include "esphome/core/component.h" -#include "esphome/core/defines.h" #include "esphome/core/helpers.h" #include "esphome/components/api/api_pb2.h" diff --git a/esphome/components/wifi/wifi_component_esp32_arduino.cpp b/esphome/components/wifi/wifi_component_esp32_arduino.cpp index f35f5dfc43..3628eca78d 100644 --- a/esphome/components/wifi/wifi_component_esp32_arduino.cpp +++ b/esphome/components/wifi/wifi_component_esp32_arduino.cpp @@ -220,7 +220,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { esp_err_t err; esp_wifi_get_config(WIFI_IF_STA, ¤t_conf); - if (memcmp(¤t_conf, &conf, sizeof(wifi_config_t)) != 0) { + if (memcmp(¤t_conf, &conf, sizeof(wifi_config_t)) != 0) { // NOLINT err = esp_wifi_disconnect(); if (err != ESP_OK) { ESP_LOGV(TAG, "esp_wifi_disconnect failed! %d", err); diff --git a/esphome/components/wifi/wifi_component_esp_idf.cpp b/esphome/components/wifi/wifi_component_esp_idf.cpp index 744fc755fe..a2bbc8ae09 100644 --- a/esphome/components/wifi/wifi_component_esp_idf.cpp +++ b/esphome/components/wifi/wifi_component_esp_idf.cpp @@ -333,7 +333,7 @@ bool WiFiComponent::wifi_sta_connect_(const WiFiAP &ap) { // can continue } - if (memcmp(¤t_conf, &conf, sizeof(wifi_config_t)) != 0) { + if (memcmp(¤t_conf, &conf, sizeof(wifi_config_t)) != 0) { // NOLINT err = esp_wifi_disconnect(); if (err != ESP_OK) { ESP_LOGV(TAG, "esp_wifi_disconnect failed: %s", esp_err_to_name(err)); diff --git a/script/clang-tidy b/script/clang-tidy index 5d2cba6eb5..d8dd033d29 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -113,7 +113,7 @@ def clang_options(idedata): def run_tidy(args, options, tmpdir, queue, lock, failed_files): while True: path = queue.get() - invocation = ["clang-tidy-11"] + invocation = ["clang-tidy-14"] if tmpdir is not None: invocation.append("--export-fixes") @@ -194,14 +194,14 @@ def main(): args = parser.parse_args() try: - get_output("clang-tidy-11", "-version") + get_output("clang-tidy-14", "-version") except: print( """ - Oops. It looks like clang-tidy-11 is not installed. + Oops. It looks like clang-tidy-14 is not installed. - Please check you can run "clang-tidy-11 -version" in your terminal and install - clang-tidy (v11) if necessary. + Please check you can run "clang-tidy-14 -version" in your terminal and install + clang-tidy (v14) if necessary. Note you can also upload your code as a pull request on GitHub and see the CI check output to apply clang-tidy. @@ -272,7 +272,7 @@ def main(): if args.fix and failed_files: print("Applying fixes ...") try: - subprocess.call(["clang-apply-replacements-11", tmpdir]) + subprocess.call(["clang-apply-replacements-14", tmpdir]) except: print("Error applying fixes.\n", file=sys.stderr) raise