Avoid non-const globals and enable clang-tidy check (#1892)

This commit is contained in:
Stefan Agner
2021-06-10 22:19:44 +02:00
committed by GitHub
parent 360effcb72
commit 501f88ca86
376 changed files with 466 additions and 468 deletions
+2 -2
View File
@@ -9,7 +9,7 @@
namespace esphome {
static const char *TAG = "app";
static const char *const TAG = "app";
void Application::register_component_(Component *comp) {
if (comp == nullptr) {
@@ -161,6 +161,6 @@ void Application::calculate_looping_components_() {
}
}
Application App;
Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esphome
+1 -1
View File
@@ -252,6 +252,6 @@ class Application {
};
/// Global storage of Application pointer - only one Application can exist.
extern Application App;
extern Application App; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esphome
+2 -2
View File
@@ -8,7 +8,7 @@
namespace esphome {
static const char *TAG = "component";
static const char *const TAG = "component";
namespace setup_priority {
@@ -36,7 +36,7 @@ const uint32_t STATUS_LED_OK = 0x0000;
const uint32_t STATUS_LED_WARNING = 0x0100;
const uint32_t STATUS_LED_ERROR = 0x0200;
uint32_t global_state = 0;
uint32_t global_state = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
float Component::get_loop_priority() const { return 0.0f; }
+1 -1
View File
@@ -18,7 +18,7 @@ void ICACHE_RAM_ATTR __detachInterrupt(uint8_t pin); // NOLINT
namespace esphome {
static const char *TAG = "esphal";
static const char *const TAG = "esphal";
GPIOPin::GPIOPin(uint8_t pin, uint8_t mode, bool inverted)
: pin_(pin),
+6 -6
View File
@@ -13,7 +13,7 @@
namespace esphome {
static const char *TAG = "helpers";
static const char *const TAG = "helpers";
std::string get_mac_address() {
char tmp[20];
@@ -55,7 +55,7 @@ double random_double() { return random_uint32() / double(UINT32_MAX); }
float random_float() { return float(random_double()); }
static uint32_t fast_random_seed = 0;
static uint32_t fast_random_seed = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void fast_random_set_seed(uint32_t seed) { fast_random_seed = seed; }
uint32_t fast_random_32() {
@@ -123,8 +123,8 @@ std::string uint32_to_string(uint32_t num) {
snprintf(buffer, sizeof(buffer), "%04X%04X", address16[1], address16[0]);
return std::string(buffer);
}
static char *global_json_build_buffer = nullptr;
static size_t global_json_build_buffer_size = 0;
static char *global_json_build_buffer = nullptr; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static size_t global_json_build_buffer_size = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void reserve_global_json_build_buffer(size_t required_size) {
if (global_json_build_buffer_size == 0 || global_json_build_buffer_size < required_size) {
@@ -154,7 +154,7 @@ ParseOnOffState parse_on_off(const char *str, const char *on, const char *off) {
return PARSE_NONE;
}
const char *HOSTNAME_CHARACTER_ALLOWLIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
const char *const HOSTNAME_CHARACTER_ALLOWLIST = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
uint8_t crc8(uint8_t *data, uint8_t len) {
uint8_t crc = 0;
@@ -271,7 +271,7 @@ template<uint32_t> uint32_t reverse_bits(uint32_t x) {
return uint32_t(reverse_bits_16(x & 0xFFFF) << 16) | uint32_t(reverse_bits_16(x >> 16));
}
static int high_freq_num_requests = 0;
static int high_freq_num_requests = 0; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
void HighFrequencyLoopRequester::start() {
if (this->started_)
+1 -1
View File
@@ -28,7 +28,7 @@
namespace esphome {
/// The characters that are allowed in a hostname.
extern const char *HOSTNAME_CHARACTER_ALLOWLIST;
extern const char *const HOSTNAME_CHARACTER_ALLOWLIST;
/// Gets the MAC address as a string, this can be used as way to identify this ESP.
std::string get_mac_address();
+3 -3
View File
@@ -15,7 +15,7 @@ extern "C" {
namespace esphome {
static const char *TAG = "preferences";
static const char *const TAG = "preferences";
ESPPreferenceObject::ESPPreferenceObject() : offset_(0), length_words_(0), type_(0), data_(nullptr) {}
ESPPreferenceObject::ESPPreferenceObject(size_t offset, size_t length, uint32_t type)
@@ -73,7 +73,7 @@ static inline bool esp_rtc_user_mem_read(uint32_t index, uint32_t *dest) {
return true;
}
static bool esp8266_flash_dirty = false;
static bool esp8266_flash_dirty = false; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
static inline bool esp_rtc_user_mem_write(uint32_t index, uint32_t value) {
if (index >= ESP_RTC_USER_MEM_SIZE_WORDS) {
@@ -303,6 +303,6 @@ uint32_t ESPPreferenceObject::calculate_crc_() const {
}
bool ESPPreferenceObject::is_initialized() const { return this->data_ != nullptr; }
ESPPreferences global_preferences;
ESPPreferences global_preferences; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
} // namespace esphome
+4 -4
View File
@@ -39,14 +39,14 @@ class ESPPreferenceObject {
#ifdef ARDUINO_ARCH_ESP8266
#ifdef USE_ESP8266_PREFERENCES_FLASH
static bool DEFAULT_IN_FLASH = true;
static const bool DEFAULT_IN_FLASH = true;
#else
static bool DEFAULT_IN_FLASH = false;
static const bool DEFAULT_IN_FLASH = false;
#endif
#endif
#ifdef ARDUINO_ARCH_ESP32
static bool DEFAULT_IN_FLASH = true;
static const bool DEFAULT_IN_FLASH = true;
#endif
class ESPPreferences {
@@ -83,7 +83,7 @@ class ESPPreferences {
#endif
};
extern ESPPreferences global_preferences;
extern ESPPreferences global_preferences; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
template<typename T> ESPPreferenceObject ESPPreferences::make_preference(uint32_t type, bool in_flash) {
return this->make_preference((sizeof(T) + 3) / 4, type, in_flash);
+1 -1
View File
@@ -5,7 +5,7 @@
namespace esphome {
static const char *TAG = "scheduler";
static const char *const TAG = "scheduler";
static const uint32_t SCHEDULER_DONT_RUN = 4294967295UL;
static const uint32_t MAX_LOGICALLY_DELETED_ITEMS = 10;
+1 -1
View File
@@ -66,7 +66,7 @@ bool mqtt_is_connected() {
bool remote_is_connected() { return api_is_connected() || mqtt_is_connected(); }
#if defined(ARDUINO_ARCH_ESP8266) && defined(USE_MDNS)
bool mdns_setup;
static bool mdns_setup; // NOLINT(cppcoreguidelines-avoid-non-const-global-variables)
#endif
#ifndef WEBSERVER_PORT