Skip to content

Commit 607601b

Browse files
authored
Enable a bunch of clang-tidy checks (esphome#2149)
1 parent f58828c commit 607601b

File tree

79 files changed

+206
-296
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+206
-296
lines changed

.clang-tidy

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ Checks: >-
55
-altera-*,
66
-android-*,
77
-boost-*,
8-
-bugprone-branch-clone,
9-
-bugprone-easily-swappable-parameters,
108
-bugprone-narrowing-conversions,
119
-bugprone-signed-char-misuse,
12-
-bugprone-too-small-loop-variable,
1310
-cert-dcl50-cpp,
1411
-cert-err58-cpp,
1512
-cert-oop57-cpp,
@@ -19,12 +16,10 @@ Checks: >-
1916
-clang-diagnostic-delete-abstract-non-virtual-dtor,
2017
-clang-diagnostic-delete-non-abstract-non-virtual-dtor,
2118
-clang-diagnostic-shadow-field,
22-
-clang-diagnostic-sign-compare,
23-
-clang-diagnostic-unused-variable,
2419
-clang-diagnostic-unused-const-variable,
20+
-clang-diagnostic-unused-parameter,
2521
-concurrency-*,
2622
-cppcoreguidelines-avoid-c-arrays,
27-
-cppcoreguidelines-avoid-goto,
2823
-cppcoreguidelines-avoid-magic-numbers,
2924
-cppcoreguidelines-init-variables,
3025
-cppcoreguidelines-macro-usage,
@@ -41,7 +36,6 @@ Checks: >-
4136
-cppcoreguidelines-pro-type-union-access,
4237
-cppcoreguidelines-pro-type-vararg,
4338
-cppcoreguidelines-special-member-functions,
44-
-fuchsia-default-arguments,
4539
-fuchsia-multiple-inheritance,
4640
-fuchsia-overloaded-operator,
4741
-fuchsia-statically-constructed-objects,

esphome/components/adalight/adalight_light_effect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void AdalightLightEffect::stop() {
2525
AddressableLightEffect::stop();
2626
}
2727

28-
int AdalightLightEffect::get_frame_size_(int led_count) const {
28+
unsigned int AdalightLightEffect::get_frame_size_(int led_count) const {
2929
// 3 bytes: Ada
3030
// 2 bytes: LED count
3131
// 1 byte: checksum

esphome/components/adalight/adalight_light_effect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AdalightLightEffect : public light::AddressableLightEffect, public uart::U
2525
CONSUMED,
2626
};
2727

28-
int get_frame_size_(int led_count) const;
28+
unsigned int get_frame_size_(int led_count) const;
2929
void reset_frame_(light::AddressableLight &it);
3030
void blank_all_leds_(light::AddressableLight &it);
3131
Frame parse_frame_(light::AddressableLight &it);

esphome/components/aht10/aht10.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,12 @@ void AHT10Component::update() {
110110
uint32_t raw_temperature = ((data[3] & 0x0F) << 16) | (data[4] << 8) | data[5];
111111
uint32_t raw_humidity = ((data[1] << 16) | (data[2] << 8) | data[3]) >> 4;
112112

113-
float temperature = ((200.0 * (float) raw_temperature) / 1048576.0) - 50.0;
113+
float temperature = ((200.0f * (float) raw_temperature) / 1048576.0f) - 50.0f;
114114
float humidity;
115115
if (raw_humidity == 0) { // unrealistic value
116116
humidity = NAN;
117117
} else {
118-
humidity = (float) raw_humidity * 100.0 / 1048576.0;
118+
humidity = (float) raw_humidity * 100.0f / 1048576.0f;
119119
}
120120

121121
if (this->temperature_sensor_ != nullptr) {

esphome/components/am2320/am2320.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ void AM2320Component::update() {
3838
return;
3939
}
4040

41-
float temperature = (((data[4] & 0x7F) << 8) + data[5]) / 10.0;
41+
float temperature = (((data[4] & 0x7F) << 8) + data[5]) / 10.0f;
4242
temperature = (data[4] & 0x80) ? -temperature : temperature;
43-
float humidity = ((data[2] << 8) + data[3]) / 10.0;
43+
float humidity = ((data[2] << 8) + data[3]) / 10.0f;
4444

4545
ESP_LOGD(TAG, "Got temperature=%.1f°C humidity=%.1f%%", temperature, humidity);
4646
if (this->temperature_sensor_ != nullptr)

esphome/components/anova/anova_base.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,7 @@ void AnovaCodec::decode(const uint8_t *data, uint16_t length) {
103103
}
104104
break;
105105
}
106-
case READ_TARGET_TEMPERATURE: {
107-
this->target_temp_ = parse_number<float>(str_until(buf, '\r')).value_or(0.0f);
108-
if (this->fahrenheit_)
109-
this->target_temp_ = ftoc(this->target_temp_);
110-
this->has_target_temp_ = true;
111-
break;
112-
}
106+
case READ_TARGET_TEMPERATURE:
113107
case SET_TARGET_TEMPERATURE: {
114108
this->target_temp_ = parse_number<float>(str_until(buf, '\r')).value_or(0.0f);
115109
if (this->fahrenheit_)

esphome/components/api/api_connection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ void APIConnection::loop() {
132132

133133
if (state_subs_at_ != -1) {
134134
const auto &subs = this->parent_->get_state_subs();
135-
if (state_subs_at_ >= subs.size()) {
135+
if (state_subs_at_ >= (int) subs.size()) {
136136
state_subs_at_ = -1;
137137
} else {
138138
auto &it = subs[state_subs_at_];

esphome/components/api/api_frame_helper.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,6 @@ APIError APINoiseFrameHelper::loop() {
174174
* errno API_ERROR_HANDSHAKE_PACKET_LEN: Packet too big for this phase.
175175
*/
176176
APIError APINoiseFrameHelper::try_read_frame_(ParsedFrame *frame) {
177-
int err;
178-
APIError aerr;
179-
180177
if (frame == nullptr) {
181178
HELPER_LOG("Bad argument for try_read_frame_");
182179
return APIError::BAD_ARG;
@@ -200,7 +197,7 @@ APIError APINoiseFrameHelper::try_read_frame_(ParsedFrame *frame) {
200197
return APIError::CONNECTION_CLOSED;
201198
}
202199
rx_header_buf_len_ += received;
203-
if (received != to_read) {
200+
if ((size_t) received != to_read) {
204201
// not a full read
205202
return APIError::WOULD_BLOCK;
206203
}
@@ -247,7 +244,7 @@ APIError APINoiseFrameHelper::try_read_frame_(ParsedFrame *frame) {
247244
return APIError::CONNECTION_CLOSED;
248245
}
249246
rx_buf_len_ += received;
250-
if (received != to_read) {
247+
if ((size_t) received != to_read) {
251248
// not all read
252249
return APIError::WOULD_BLOCK;
253250
}
@@ -544,7 +541,6 @@ APIError APINoiseFrameHelper::try_send_tx_buf_() {
544541
APIError APINoiseFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) {
545542
if (iovcnt == 0)
546543
return APIError::OK;
547-
int err;
548544
APIError aerr;
549545

550546
size_t total_write_len = 0;
@@ -584,7 +580,7 @@ APIError APINoiseFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) {
584580
state_ = State::FAILED;
585581
HELPER_LOG("Socket write failed with errno %d", errno);
586582
return APIError::SOCKET_WRITE_FAILED;
587-
} else if (sent != total_write_len) {
583+
} else if ((size_t) sent != total_write_len) {
588584
// partially sent, add end to tx_buf
589585
size_t to_consume = sent;
590586
for (int i = 0; i < iovcnt; i++) {
@@ -778,9 +774,6 @@ APIError APIPlaintextFrameHelper::loop() {
778774
* error API_ERROR_BAD_INDICATOR: Bad indicator byte at start of frame.
779775
*/
780776
APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
781-
int err;
782-
APIError aerr;
783-
784777
if (frame == nullptr) {
785778
HELPER_LOG("Bad argument for try_read_frame_");
786779
return APIError::BAD_ARG;
@@ -854,7 +847,7 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
854847
return APIError::CONNECTION_CLOSED;
855848
}
856849
rx_buf_len_ += received;
857-
if (received != to_read) {
850+
if ((size_t) received != to_read) {
858851
// not all read
859852
return APIError::WOULD_BLOCK;
860853
}
@@ -874,7 +867,6 @@ APIError APIPlaintextFrameHelper::try_read_frame_(ParsedFrame *frame) {
874867
}
875868

876869
APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) {
877-
int err;
878870
APIError aerr;
879871

880872
if (state_ != State::DATA) {
@@ -894,9 +886,6 @@ APIError APIPlaintextFrameHelper::read_packet(ReadPacketBuffer *buffer) {
894886
}
895887
bool APIPlaintextFrameHelper::can_write_without_blocking() { return state_ == State::DATA && tx_buf_.empty(); }
896888
APIError APIPlaintextFrameHelper::write_packet(uint16_t type, const uint8_t *payload, size_t payload_len) {
897-
int err;
898-
APIError aerr;
899-
900889
if (state_ != State::DATA) {
901890
return APIError::BAD_STATE;
902891
}
@@ -940,7 +929,6 @@ APIError APIPlaintextFrameHelper::try_send_tx_buf_() {
940929
APIError APIPlaintextFrameHelper::write_raw_(const struct iovec *iov, int iovcnt) {
941930
if (iovcnt == 0)
942931
return APIError::OK;
943-
int err;
944932
APIError aerr;
945933

946934
size_t total_write_len = 0;
@@ -980,7 +968,7 @@ APIError APIPlaintextFrameHelper::write_raw_(const struct iovec *iov, int iovcnt
980968
state_ = State::FAILED;
981969
HELPER_LOG("Socket write failed with errno %d", errno);
982970
return APIError::SOCKET_WRITE_FAILED;
983-
} else if (sent != total_write_len) {
971+
} else if ((size_t) sent != total_write_len) {
984972
// partially sent, add end to tx_buf
985973
size_t to_consume = sent;
986974
for (int i = 0; i < iovcnt; i++) {

0 commit comments

Comments
 (0)