diff --git a/.clang-tidy b/.clang-tidy index 8451a2bdd4..890eb18608 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -63,11 +63,15 @@ Checks: >- -misc-no-recursion, -misc-unused-parameters, -modernize-avoid-c-arrays, + -modernize-avoid-bind, + -modernize-concat-nested-namespaces, -modernize-return-braced-init-list, -modernize-use-auto, -modernize-use-default-member-init, -modernize-use-equals-default, -modernize-use-trailing-return-type, + -modernize-make-unique, + -modernize-use-nodiscard, -mpi-*, -objc-*, -readability-braces-around-statements, @@ -86,7 +90,6 @@ Checks: >- -readability-redundant-string-init, -readability-uppercase-literal-suffix, -readability-use-anyofallof, - -warnings-as-errors WarningsAsErrors: '*' AnalyzeTemporaryDtors: false FormatStyle: google diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb93c36d19..b00e1b3835 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -36,7 +36,7 @@ jobs: # cpp lint job runs with esphome-lint docker image so that clang-format-* # doesn't have to be installed - container: ghcr.io/esphome/esphome-lint:1.1 + container: ghcr.io/esphome/esphome-lint:1.2 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/docker-lint-build.yml b/.github/workflows/docker-lint-build.yml index 32aec87cdd..8350d4c719 100644 --- a/.github/workflows/docker-lint-build.yml +++ b/.github/workflows/docker-lint-build.yml @@ -29,7 +29,7 @@ jobs: python-version: '3.9' - name: Set TAG run: | - echo "TAG=1.1" >> $GITHUB_ENV + echo "TAG=1.2" >> $GITHUB_ENV - name: Run build run: | @@ -74,7 +74,7 @@ jobs: python-version: '3.9' - name: Set TAG run: | - echo "TAG=1.1" >> $GITHUB_ENV + echo "TAG=1.2" >> $GITHUB_ENV - name: Enable experimental manifest support run: | mkdir -p ~/.docker diff --git a/docker/Dockerfile.dev b/docker/Dockerfile.dev index 27eaa18da9..c646ce989b 100644 --- a/docker/Dockerfile.dev +++ b/docker/Dockerfile.dev @@ -1 +1 @@ -FROM esphome/esphome-lint:1.1 +FROM esphome/esphome-lint:1.2 diff --git a/docker/build.py b/docker/build.py index 54a279f845..039d7dc15b 100755 --- a/docker/build.py +++ b/docker/build.py @@ -24,7 +24,7 @@ TYPE_LINT = 'lint' TYPES = [TYPE_DOCKER, TYPE_HA_ADDON, TYPE_LINT] -BASE_VERSION = "3.6.0" +BASE_VERSION = "4.1.1" parser = argparse.ArgumentParser() diff --git a/esphome/components/adc/adc_sensor.cpp b/esphome/components/adc/adc_sensor.cpp index 78f12a6b9e..4106a0c49b 100644 --- a/esphome/components/adc/adc_sensor.cpp +++ b/esphome/components/adc/adc_sensor.cpp @@ -148,7 +148,7 @@ float ADCSensor::sample() { #ifdef ARDUINO_ARCH_ESP8266 #ifdef USE_ADC_SENSOR_VCC - return ESP.getVcc() / 1024.0f; + return ESP.getVcc() / 1024.0f; // NOLINT(readability-static-accessed-through-instance) #else return analogRead(this->pin_) / 1024.0f; // NOLINT #endif diff --git a/esphome/components/debug/debug_component.cpp b/esphome/components/debug/debug_component.cpp index 668792c7b1..11590a0978 100644 --- a/esphome/components/debug/debug_component.cpp +++ b/esphome/components/debug/debug_component.cpp @@ -21,11 +21,11 @@ void DebugComponent::dump_config() { #endif ESP_LOGD(TAG, "ESPHome version %s", ESPHOME_VERSION); - this->free_heap_ = ESP.getFreeHeap(); + this->free_heap_ = ESP.getFreeHeap(); // NOLINT(readability-static-accessed-through-instance) ESP_LOGD(TAG, "Free Heap Size: %u bytes", this->free_heap_); const char *flash_mode; - switch (ESP.getFlashChipMode()) { + switch (ESP.getFlashChipMode()) { // NOLINT(readability-static-accessed-through-instance) case FM_QIO: flash_mode = "QIO"; break; @@ -49,6 +49,7 @@ void DebugComponent::dump_config() { default: flash_mode = "UNKNOWN"; } + // NOLINTNEXTLINE(readability-static-accessed-through-instance) ESP_LOGD(TAG, "Flash Chip: Size=%ukB Speed=%uMHz Mode=%s", ESP.getFlashChipSize() / 1024, ESP.getFlashChipSpeed() / 1000000, flash_mode); @@ -87,7 +88,7 @@ void DebugComponent::dump_config() { ESP_LOGD(TAG, "ESP-IDF Version: %s", esp_get_idf_version()); - std::string mac = uint64_to_string(ESP.getEfuseMac()); + std::string mac = uint64_to_string(ESP.getEfuseMac()); // NOLINT(readability-static-accessed-through-instance) ESP_LOGD(TAG, "EFuse MAC: %s", mac.c_str()); const char *reset_reason; @@ -186,7 +187,7 @@ void DebugComponent::dump_config() { ESP_LOGD(TAG, "Wakeup Reason: %s", wakeup_reason); #endif -#ifdef ARDUINO_ARCH_ESP8266 +#if defined(ARDUINO_ARCH_ESP8266) && !defined(CLANG_TIDY) ESP_LOGD(TAG, "Chip ID: 0x%08X", ESP.getChipId()); ESP_LOGD(TAG, "SDK Version: %s", ESP.getSdkVersion()); ESP_LOGD(TAG, "Core Version: %s", ESP.getCoreVersion().c_str()); @@ -198,7 +199,7 @@ void DebugComponent::dump_config() { #endif } void DebugComponent::loop() { - uint32_t new_free_heap = ESP.getFreeHeap(); + uint32_t new_free_heap = ESP.getFreeHeap(); // NOLINT(readability-static-accessed-through-instance) if (new_free_heap < this->free_heap_ / 2) { this->free_heap_ = new_free_heap; ESP_LOGD(TAG, "Free Heap Size: %u bytes", this->free_heap_); diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index de5672759a..00f660f41a 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -84,7 +84,7 @@ void DeepSleepComponent::begin_sleep(bool manual) { #endif #ifdef ARDUINO_ARCH_ESP8266 - ESP.deepSleep(*this->sleep_duration_); + ESP.deepSleep(*this->sleep_duration_); // NOLINT(readability-static-accessed-through-instance) #endif } float DeepSleepComponent::get_setup_priority() const { return setup_priority::LATE; } diff --git a/esphome/components/http_request/http_request.cpp b/esphome/components/http_request/http_request.cpp index bf5b24c4f2..0d4e425147 100644 --- a/esphome/components/http_request/http_request.cpp +++ b/esphome/components/http_request/http_request.cpp @@ -1,4 +1,5 @@ #include "http_request.h" +#include "esphome/core/macros.h" #include "esphome/core/log.h" namespace esphome { @@ -31,11 +32,15 @@ void HttpRequestComponent::send(const std::vector begin_status = this->client_.begin(url); #endif #ifdef ARDUINO_ARCH_ESP8266 -#ifndef CLANG_TIDY +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 7, 0) + this->client_.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); +#elif ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) this->client_.setFollowRedirects(true); - this->client_.setRedirectLimit(3); - begin_status = this->client_.begin(*this->get_wifi_client_(), url); #endif +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) + this->client_.setRedirectLimit(3); +#endif + begin_status = this->client_.begin(*this->get_wifi_client_(), url); #endif if (!begin_status) { diff --git a/esphome/components/light/light_color_values.h b/esphome/components/light/light_color_values.h index dd74c396c6..ffbe378ee3 100644 --- a/esphome/components/light/light_color_values.h +++ b/esphome/components/light/light_color_values.h @@ -2,6 +2,7 @@ #include "esphome/core/helpers.h" #include "color_mode.h" +#include namespace esphome { namespace light { diff --git a/esphome/components/neopixelbus/light.py b/esphome/components/neopixelbus/light.py index 59d784a614..575f69b731 100644 --- a/esphome/components/neopixelbus/light.py +++ b/esphome/components/neopixelbus/light.py @@ -205,4 +205,4 @@ async def to_code(config): cg.add(var.set_pixel_order(getattr(ESPNeoPixelOrder, config[CONF_TYPE]))) # https://github.com/Makuna/NeoPixelBus/blob/master/library.json - cg.add_library("NeoPixelBus-esphome", "2.6.2") + cg.add_library("NeoPixelBus", "2.6.7") diff --git a/esphome/components/nextion/nextion_upload.cpp b/esphome/components/nextion/nextion_upload.cpp index 35b904357b..f864a397cc 100644 --- a/esphome/components/nextion/nextion_upload.cpp +++ b/esphome/components/nextion/nextion_upload.cpp @@ -1,6 +1,7 @@ #include "nextion.h" #include "esphome/core/application.h" +#include "esphome/core/macros.h" #include "esphome/core/util.h" #include "esphome/core/log.h" @@ -26,8 +27,12 @@ int Nextion::upload_by_chunks_(HTTPClient *http, int range_start) { range_end = this->tft_size_; #ifdef ARDUINO_ARCH_ESP8266 -#ifndef CLANG_TIDY +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 7, 0) http->setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); +#elif ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) + http->setFollowRedirects(true); +#endif +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) http->setRedirectLimit(3); #endif #endif @@ -44,10 +49,8 @@ int Nextion::upload_by_chunks_(HTTPClient *http, int range_start) { #ifdef ARDUINO_ARCH_ESP32 begin_status = http->begin(this->tft_url_.c_str()); #endif -#ifndef CLANG_TIDY #ifdef ARDUINO_ARCH_ESP8266 begin_status = http->begin(*this->get_wifi_client_(), this->tft_url_.c_str()); -#endif #endif ++tries; @@ -140,11 +143,15 @@ void Nextion::upload_tft() { begin_status = http.begin(this->tft_url_.c_str()); #endif #ifdef ARDUINO_ARCH_ESP8266 -#ifndef CLANG_TIDY +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 7, 0) http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); - http.setRedirectLimit(3); - begin_status = http.begin(*this->get_wifi_client_(), this->tft_url_.c_str()); +#elif ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) + http.setFollowRedirects(true); #endif +#if ARDUINO_VERSION_CODE >= VERSION_CODE(2, 6, 0) + http.setRedirectLimit(3); +#endif + begin_status = http.begin(*this->get_wifi_client_(), this->tft_url_.c_str()); #endif if (!begin_status) { @@ -256,6 +263,7 @@ void Nextion::upload_tft() { } } #else + // NOLINTNEXTLINE(readability-static-accessed-through-instance) uint32_t chunk_size = ESP.getFreeHeap() < 10240 ? 4096 : 8192; #endif @@ -270,6 +278,7 @@ void Nextion::upload_tft() { } } else { #endif + // NOLINTNEXTLINE(readability-static-accessed-through-instance) ESP_LOGD(TAG, "Allocating buffer size %d, Heap size is %u", chunk_size, ESP.getFreeHeap()); this->transfer_buffer_ = new (std::nothrow) uint8_t[chunk_size]; // NOLINT(cppcoreguidelines-owning-memory) if (this->transfer_buffer_ == nullptr) { // Try a smaller size @@ -288,6 +297,7 @@ void Nextion::upload_tft() { this->transfer_buffer_size_ = chunk_size; } + // NOLINTNEXTLINE(readability-static-accessed-through-instance) ESP_LOGD(TAG, "Updating tft from \"%s\" with a file size of %d using %zu chunksize, Heap Size %d", this->tft_url_.c_str(), this->content_length_, this->transfer_buffer_size_, ESP.getFreeHeap()); @@ -299,6 +309,7 @@ void Nextion::upload_tft() { this->upload_end_(); } App.feed_wdt(); + // NOLINTNEXTLINE(readability-static-accessed-through-instance) ESP_LOGD(TAG, "Heap Size %d, Bytes left %d", ESP.getFreeHeap(), this->content_length_); } ESP_LOGD(TAG, "Successfully updated Nextion!"); @@ -311,7 +322,7 @@ void Nextion::upload_end_() { this->soft_reset(); delay(1500); // NOLINT ESP_LOGD(TAG, "Restarting esphome"); - ESP.restart(); + ESP.restart(); // NOLINT(readability-static-accessed-through-instance) } #ifdef ARDUINO_ARCH_ESP8266 diff --git a/esphome/components/nfc/ndef_message.cpp b/esphome/components/nfc/ndef_message.cpp index b1554f41ae..147392940c 100644 --- a/esphome/components/nfc/ndef_message.cpp +++ b/esphome/components/nfc/ndef_message.cpp @@ -83,11 +83,11 @@ bool NdefMessage::add_text_record(const std::string &text) { return this->add_te bool NdefMessage::add_text_record(const std::string &text, const std::string &encoding) { std::string payload = to_string(text.length()) + encoding + text; - return this->add_record(make_unique(TNF_WELL_KNOWN, "T", payload)); + return this->add_record(std::unique_ptr{new NdefRecord(TNF_WELL_KNOWN, "T", payload)}); } bool NdefMessage::add_uri_record(const std::string &uri) { - return this->add_record(make_unique(TNF_WELL_KNOWN, "U", uri)); + return this->add_record(std::unique_ptr{new NdefRecord(TNF_WELL_KNOWN, "U", uri)}); } std::vector NdefMessage::encode() { diff --git a/esphome/components/nfc/nfc_tag.h b/esphome/components/nfc/nfc_tag.h index ab6ca650e4..2c8b0a5f21 100644 --- a/esphome/components/nfc/nfc_tag.h +++ b/esphome/components/nfc/nfc_tag.h @@ -31,13 +31,13 @@ class NfcTag { NfcTag(std::vector &uid, const std::string &tag_type, std::vector &ndef_data) { this->uid_ = uid; this->tag_type_ = tag_type; - this->ndef_message_ = make_unique(ndef_data); + this->ndef_message_ = std::unique_ptr(new NdefMessage(ndef_data)); }; NfcTag(const NfcTag &rhs) { uid_ = rhs.uid_; tag_type_ = rhs.tag_type_; if (rhs.ndef_message_ != nullptr) - ndef_message_ = make_unique(*rhs.ndef_message_); + ndef_message_ = std::unique_ptr(new NdefMessage(*rhs.ndef_message_)); } std::vector &get_uid() { return this->uid_; }; diff --git a/esphome/components/pn532/pn532.cpp b/esphome/components/pn532/pn532.cpp index 8fda19cba3..c28ce8d503 100644 --- a/esphome/components/pn532/pn532.cpp +++ b/esphome/components/pn532/pn532.cpp @@ -104,7 +104,7 @@ void PN532::loop() { if (!success) { // Something failed if (!this->current_uid_.empty()) { - auto tag = make_unique(this->current_uid_); + auto tag = std::unique_ptr{new nfc::NfcTag(this->current_uid_)}; for (auto *trigger : this->triggers_ontagremoved_) trigger->process(tag); } @@ -117,7 +117,7 @@ void PN532::loop() { if (num_targets != 1) { // no tags found or too many if (!this->current_uid_.empty()) { - auto tag = make_unique(this->current_uid_); + auto tag = std::unique_ptr{new nfc::NfcTag(this->current_uid_)}; for (auto *trigger : this->triggers_ontagremoved_) trigger->process(tag); } @@ -281,9 +281,9 @@ std::unique_ptr PN532::read_tag_(std::vector &uid) { return this->read_mifare_ultralight_tag_(uid); } else if (type == nfc::TAG_TYPE_UNKNOWN) { ESP_LOGV(TAG, "Cannot determine tag type"); - return make_unique(uid); + return std::unique_ptr{new nfc::NfcTag(uid)}; } else { - return make_unique(uid); + return std::unique_ptr{new nfc::NfcTag(uid)}; } } diff --git a/esphome/components/pn532/pn532_mifare_classic.cpp b/esphome/components/pn532/pn532_mifare_classic.cpp index fa99e5cfab..f4bd11d49f 100644 --- a/esphome/components/pn532/pn532_mifare_classic.cpp +++ b/esphome/components/pn532/pn532_mifare_classic.cpp @@ -15,15 +15,15 @@ std::unique_ptr PN532::read_mifare_classic_tag_(std::vector data; if (this->read_mifare_classic_block_(current_block, data)) { if (!nfc::decode_mifare_classic_tlv(data, message_length, message_start_index)) { - return make_unique(uid, nfc::ERROR); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::ERROR)}; } } else { ESP_LOGE(TAG, "Failed to read block %d", current_block); - return make_unique(uid, nfc::MIFARE_CLASSIC); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC)}; } } else { ESP_LOGV(TAG, "Tag is not NDEF formatted"); - return make_unique(uid, nfc::MIFARE_CLASSIC); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC)}; } uint32_t index = 0; @@ -51,7 +51,7 @@ std::unique_ptr PN532::read_mifare_classic_tag_(std::vector(uid, nfc::MIFARE_CLASSIC, buffer); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::MIFARE_CLASSIC, buffer)}; } bool PN532::read_mifare_classic_block_(uint8_t block_num, std::vector &data) { diff --git a/esphome/components/pn532/pn532_mifare_ultralight.cpp b/esphome/components/pn532/pn532_mifare_ultralight.cpp index 6f118419ba..24e97ab95c 100644 --- a/esphome/components/pn532/pn532_mifare_ultralight.cpp +++ b/esphome/components/pn532/pn532_mifare_ultralight.cpp @@ -9,25 +9,25 @@ static const char *const TAG = "pn532.mifare_ultralight"; std::unique_ptr PN532::read_mifare_ultralight_tag_(std::vector &uid) { if (!this->is_mifare_ultralight_formatted_()) { ESP_LOGD(TAG, "Not NDEF formatted"); - return make_unique(uid, nfc::NFC_FORUM_TYPE_2); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)}; } uint8_t message_length; uint8_t message_start_index; if (!this->find_mifare_ultralight_ndef_(message_length, message_start_index)) { - return make_unique(uid, nfc::NFC_FORUM_TYPE_2); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)}; } ESP_LOGVV(TAG, "message length: %d, start: %d", message_length, message_start_index); if (message_length == 0) { - return make_unique(uid, nfc::NFC_FORUM_TYPE_2); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)}; } std::vector data; for (uint8_t page = nfc::MIFARE_ULTRALIGHT_DATA_START_PAGE; page < nfc::MIFARE_ULTRALIGHT_MAX_PAGE; page++) { std::vector page_data; if (!this->read_mifare_ultralight_page_(page, page_data)) { ESP_LOGE(TAG, "Error reading page %d", page); - return make_unique(uid, nfc::NFC_FORUM_TYPE_2); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2)}; } data.insert(data.end(), page_data.begin(), page_data.end()); @@ -38,7 +38,7 @@ std::unique_ptr PN532::read_mifare_ultralight_tag_(std::vector(uid, nfc::NFC_FORUM_TYPE_2, data); + return std::unique_ptr{new nfc::NfcTag(uid, nfc::NFC_FORUM_TYPE_2, data)}; } bool PN532::read_mifare_ultralight_page_(uint8_t page_num, std::vector &data) { diff --git a/esphome/components/sgp40/sgp40.cpp b/esphome/components/sgp40/sgp40.cpp index a911c107b9..1a1909eeb0 100644 --- a/esphome/components/sgp40/sgp40.cpp +++ b/esphome/components/sgp40/sgp40.cpp @@ -1,5 +1,6 @@ #include "esphome/core/log.h" #include "sgp40.h" +#include namespace esphome { namespace sgp40 { diff --git a/esphome/components/shutdown/shutdown_switch.cpp b/esphome/components/shutdown/shutdown_switch.cpp index 3cc8ba9e1b..87b755cab6 100644 --- a/esphome/components/shutdown/shutdown_switch.cpp +++ b/esphome/components/shutdown/shutdown_switch.cpp @@ -18,7 +18,7 @@ void ShutdownSwitch::write_state(bool state) { App.run_safe_shutdown_hooks(); #ifdef ARDUINO_ARCH_ESP8266 - ESP.deepSleep(0); + ESP.deepSleep(0); // NOLINT(readability-static-accessed-through-instance) #endif #ifdef ARDUINO_ARCH_ESP32 esp_deep_sleep_start(); diff --git a/esphome/components/spi/spi.cpp b/esphome/components/spi/spi.cpp index 609b4df456..3180447711 100644 --- a/esphome/components/spi/spi.cpp +++ b/esphome/components/spi/spi.cpp @@ -95,12 +95,12 @@ void SPIComponent::debug_rx(uint8_t value) { void SPIComponent::debug_enable(uint8_t pin) { ESP_LOGVV(TAG, "Enabling SPI Chip on pin %u...", pin); } void SPIComponent::cycle_clock_(bool value) { - uint32_t start = ESP.getCycleCount(); - while (start - ESP.getCycleCount() < this->wait_cycle_) + uint32_t start = ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance) + while (start - ESP.getCycleCount() < this->wait_cycle_) // NOLINT(readability-static-accessed-through-instance) ; this->clk_->digital_write(value); start += this->wait_cycle_; - while (start - ESP.getCycleCount() < this->wait_cycle_) + while (start - ESP.getCycleCount() < this->wait_cycle_) // NOLINT(readability-static-accessed-through-instance) ; } diff --git a/esphome/components/time/automation.cpp b/esphome/components/time/automation.cpp index 84cc76a762..f133ab021c 100644 --- a/esphome/components/time/automation.cpp +++ b/esphome/components/time/automation.cpp @@ -43,9 +43,9 @@ void CronTrigger::loop() { this->last_check_ = time; if (!time.fields_in_range()) { ESP_LOGW(TAG, "Time is out of range!"); - ESP_LOGD(TAG, "Second=%02u Minute=%02u Hour=%02u DayOfWeek=%u DayOfMonth=%u DayOfYear=%u Month=%u time=%ld", + ESP_LOGD(TAG, "Second=%02u Minute=%02u Hour=%02u DayOfWeek=%u DayOfMonth=%u DayOfYear=%u Month=%u time=%" PRId64, time.second, time.minute, time.hour, time.day_of_week, time.day_of_month, time.day_of_year, time.month, - time.timestamp); + (int64_t) time.timestamp); } if (this->matches(time)) diff --git a/esphome/components/uart/uart_esp8266.cpp b/esphome/components/uart/uart_esp8266.cpp index 6d207fde6c..a74f2601e4 100644 --- a/esphome/components/uart/uart_esp8266.cpp +++ b/esphome/components/uart/uart_esp8266.cpp @@ -233,7 +233,7 @@ void ESP8266SoftwareSerial::setup(int8_t tx_pin, int8_t rx_pin, uint32_t baud_ra } void ICACHE_RAM_ATTR ESP8266SoftwareSerial::gpio_intr(ESP8266SoftwareSerial *arg) { uint32_t wait = arg->bit_time_ + arg->bit_time_ / 3 - 500; - const uint32_t start = ESP.getCycleCount(); + const uint32_t start = ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance) uint8_t rec = 0; // Manually unroll the loop for (int i = 0; i < arg->data_bits_; i++) @@ -273,7 +273,7 @@ void ICACHE_RAM_ATTR HOT ESP8266SoftwareSerial::write_byte(uint8_t data) { { InterruptLock lock; uint32_t wait = this->bit_time_; - const uint32_t start = ESP.getCycleCount(); + const uint32_t start = ESP.getCycleCount(); // NOLINT(readability-static-accessed-through-instance) // Start bit this->write_bit_(false, &wait, start); for (int i = 0; i < this->data_bits_; i++) { @@ -291,7 +291,7 @@ void ICACHE_RAM_ATTR HOT ESP8266SoftwareSerial::write_byte(uint8_t data) { } } void ICACHE_RAM_ATTR ESP8266SoftwareSerial::wait_(uint32_t *wait, const uint32_t &start) { - while (ESP.getCycleCount() - start < *wait) + while (ESP.getCycleCount() - start < *wait) // NOLINT(readability-static-accessed-through-instance) ; *wait += this->bit_time_; } diff --git a/esphome/components/web_server_base/web_server_base.cpp b/esphome/components/web_server_base/web_server_base.cpp index 9f04c3b7bf..6351941aee 100644 --- a/esphome/components/web_server_base/web_server_base.cpp +++ b/esphome/components/web_server_base/web_server_base.cpp @@ -29,6 +29,7 @@ void OTARequestHandler::handleUpload(AsyncWebServerRequest *request, const Strin this->ota_read_length_ = 0; #ifdef ARDUINO_ARCH_ESP8266 Update.runAsync(true); + // NOLINTNEXTLINE(readability-static-accessed-through-instance) success = Update.begin((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000); #endif #ifdef ARDUINO_ARCH_ESP32 diff --git a/esphome/core/application.cpp b/esphome/core/application.cpp index c0f68d80d6..5ab1d973f4 100644 --- a/esphome/core/application.cpp +++ b/esphome/core/application.cpp @@ -127,7 +127,7 @@ void Application::reboot() { ESP_LOGI(TAG, "Forcing a reboot..."); for (auto *comp : this->components_) comp->on_shutdown(); - ESP.restart(); + ESP.restart(); // NOLINT(readability-static-accessed-through-instance) // restart() doesn't always end execution while (true) { yield(); @@ -139,7 +139,7 @@ void Application::safe_reboot() { comp->on_safe_shutdown(); for (auto *comp : this->components_) comp->on_shutdown(); - ESP.restart(); + ESP.restart(); // NOLINT(readability-static-accessed-through-instance) // restart() doesn't always end execution while (true) { yield(); diff --git a/esphome/core/application_esp8266.cpp b/esphome/core/application_esp8266.cpp index 95139ca112..ee32417634 100644 --- a/esphome/core/application_esp8266.cpp +++ b/esphome/core/application_esp8266.cpp @@ -6,7 +6,9 @@ namespace esphome { static const char *const TAG = "app_esp8266"; -void ICACHE_RAM_ATTR HOT Application::feed_wdt_arch_() { ESP.wdtFeed(); } +void ICACHE_RAM_ATTR HOT Application::feed_wdt_arch_() { + ESP.wdtFeed(); // NOLINT(readability-static-accessed-through-instance) +} } // namespace esphome #endif diff --git a/esphome/core/helpers.h b/esphome/core/helpers.h index 044de6c8b0..86c70088d4 100644 --- a/esphome/core/helpers.h +++ b/esphome/core/helpers.h @@ -12,13 +12,6 @@ #include "esphome/core/optional.h" -#ifdef CLANG_TIDY -#undef ICACHE_RAM_ATTR -#define ICACHE_RAM_ATTR -#undef ICACHE_RODATA_ATTR -#define ICACHE_RODATA_ATTR -#endif - #define HOT __attribute__((hot)) #define ESPDEPRECATED(msg, when) __attribute__((deprecated(msg))) #define ALWAYS_INLINE __attribute__((always_inline)) diff --git a/esphome/core/util.cpp b/esphome/core/util.cpp index 67e575e1c5..e0132e2e4a 100644 --- a/esphome/core/util.cpp +++ b/esphome/core/util.cpp @@ -75,12 +75,12 @@ static const uint8_t WEBSERVER_PORT = 80; #ifdef USE_MDNS #ifdef ARDUINO_ARCH_ESP8266 -void network_setup_mdns(IPAddress address, int interface) { +void network_setup_mdns(const IPAddress &address, int interface) { // Latest arduino framework breaks mDNS for AP interface // see https://github.com/esp8266/Arduino/issues/6114 if (interface == 1) return; - MDNS.begin(App.get_name().c_str(), std::move(address)); + MDNS.begin(App.get_name().c_str(), address); mdns_setup = true; #endif #ifdef ARDUINO_ARCH_ESP32 diff --git a/esphome/core/util.h b/esphome/core/util.h index 2d58eff893..764c6aaf03 100644 --- a/esphome/core/util.h +++ b/esphome/core/util.h @@ -21,7 +21,7 @@ bool remote_is_connected(); /// Manually set up the network stack (outside of the App.setup() loop, for example in OTA safe mode) #ifdef ARDUINO_ARCH_ESP8266 -void network_setup_mdns(IPAddress address, int interface); +void network_setup_mdns(const IPAddress &address, int interface); #endif #ifdef ARDUINO_ARCH_ESP32 void network_setup_mdns(); diff --git a/platformio.ini b/platformio.ini index a35e0c10fe..3b1241f282 100644 --- a/platformio.ini +++ b/platformio.ini @@ -30,7 +30,7 @@ lib_deps = ArduinoJson-esphomelib@5.13.3 esphome/ESPAsyncWebServer-esphome@1.3.0 FastLED@3.3.2 - NeoPixelBus-esphome@2.6.2 + NeoPixelBus@2.6.7 1655@1.0.2 ; TinyGPSPlus (has name conflict) 6865@1.0.0 ; TM1651 Battery Display 6306@1.0.3 ; HM3301 @@ -47,8 +47,7 @@ src_filter = +<.temp/all-include.cpp> [common:esp8266] -; use Arduino framework v2.4.2 for clang-tidy (latest 2.5.2 breaks static code analysis, see #760) -platform = platformio/espressif8266@1.8.0 +platform = platformio/espressif8266@3.1.0 framework = arduino board = nodemcuv2 lib_deps = diff --git a/script/clang-tidy b/script/clang-tidy index a63ebc674a..463959fa5d 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -27,6 +27,21 @@ def clang_options(idedata): # disable built-in include directories from the host '-nostdinc', '-nostdinc++', + # replace pgmspace.h, as it uses GNU extensions clang doesn't support + # https://github.com/earlephilhower/newlib-xtensa/pull/18 + '-D_PGMSPACE_H_', + '-Dpgm_read_byte(s)=(*(const uint8_t *)(s))', + '-Dpgm_read_byte_near(s)=(*(const uint8_t *)(s))', + '-Dpgm_read_dword(s)=(*(const uint32_t *)(s))', + '-DPROGMEM=', + '-DPGM_P=const char *', + '-DPSTR(s)=(s)', + # this next one is also needed with upstream pgmspace.h + # suppress warning about identifier naming in expansion of this macro + '-DPSTRN(s, n)=(s)', + # suppress warning about attribute cannot be applied to type + # https://github.com/esp8266/Arduino/pull/8258 + '-Ddeprecated(x)=', # pretend we're an Xtensa compiler, which gates some features in the headers '-D__XTENSA__', # allow to condition code on the presence of clang-tidy