mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 21:14:52 +01:00
Use Clang 11 (#1846)
This commit is contained in:
parent
4711f36a1f
commit
13fe9e83fa
7 changed files with 74 additions and 32 deletions
40
.clang-tidy
40
.clang-tidy
|
@ -4,14 +4,37 @@ Checks: >-
|
|||
-abseil-*,
|
||||
-android-*,
|
||||
-boost-*,
|
||||
-bugprone-branch-clone,
|
||||
-bugprone-macro-parentheses,
|
||||
-bugprone-narrowing-conversions,
|
||||
-bugprone-reserved-identifier,
|
||||
-bugprone-signed-char-misuse,
|
||||
-bugprone-suspicious-include,
|
||||
-bugprone-too-small-loop-variable,
|
||||
-bugprone-unhandled-self-assignment,
|
||||
-cert-dcl37-c,
|
||||
-cert-dcl50-cpp,
|
||||
-cert-dcl51-cpp,
|
||||
-cert-err58-cpp,
|
||||
-cert-oop54-cpp,
|
||||
-cert-oop57-cpp,
|
||||
-cert-str34-c,
|
||||
-clang-analyzer-core.CallAndMessage,
|
||||
-clang-analyzer-deadcode.DeadStores,
|
||||
-clang-analyzer-optin.*,
|
||||
-clang-analyzer-osx.*,
|
||||
-clang-analyzer-security.*,
|
||||
-clang-diagnostic-fortify-source,
|
||||
-clang-diagnostic-shadow-field,
|
||||
-cppcoreguidelines-avoid-c-arrays,
|
||||
-cppcoreguidelines-avoid-goto,
|
||||
-cppcoreguidelines-avoid-magic-numbers,
|
||||
-cppcoreguidelines-avoid-non-const-global-variables,
|
||||
-cppcoreguidelines-c-copy-assignment-signature,
|
||||
-cppcoreguidelines-init-variables,
|
||||
-cppcoreguidelines-macro-usage,
|
||||
-cppcoreguidelines-narrowing-conversions,
|
||||
-cppcoreguidelines-non-private-member-variables-in-classes,
|
||||
-cppcoreguidelines-owning-memory,
|
||||
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
|
||||
-cppcoreguidelines-pro-bounds-constant-array-index,
|
||||
|
@ -37,10 +60,16 @@ Checks: >-
|
|||
-google-runtime-int,
|
||||
-google-runtime-references,
|
||||
-hicpp-*,
|
||||
-llvm-else-after-return,
|
||||
-llvm-header-guard,
|
||||
-llvm-include-order,
|
||||
-llvm-qualified-auto,
|
||||
-llvmlibc-*,
|
||||
-misc-non-private-member-variables-in-classes,
|
||||
-misc-no-recursion,
|
||||
-misc-unconventional-assign-operator,
|
||||
-misc-unused-parameters,
|
||||
-modernize-avoid-c-arrays,
|
||||
-modernize-deprecated-headers,
|
||||
-modernize-pass-by-value,
|
||||
-modernize-pass-by-value,
|
||||
|
@ -48,14 +77,25 @@ Checks: >-
|
|||
-modernize-use-auto,
|
||||
-modernize-use-default-member-init,
|
||||
-modernize-use-equals-default,
|
||||
-modernize-use-trailing-return-type,
|
||||
-mpi-*,
|
||||
-objc-*,
|
||||
-performance-unnecessary-value-param,
|
||||
-readability-braces-around-statements,
|
||||
-readability-const-return-type,
|
||||
-readability-convert-member-functions-to-static,
|
||||
-readability-else-after-return,
|
||||
-readability-implicit-bool-conversion,
|
||||
-readability-isolate-declaration,
|
||||
-readability-magic-numbers,
|
||||
-readability-make-member-function-const,
|
||||
-readability-named-parameter,
|
||||
-readability-qualified-auto,
|
||||
-readability-redundant-access-specifiers,
|
||||
-readability-redundant-member-init,
|
||||
-readability-redundant-string-init,
|
||||
-readability-uppercase-literal-suffix,
|
||||
-readability-use-anyofallof,
|
||||
-warnings-as-errors,
|
||||
-zircon-*
|
||||
WarningsAsErrors: '*'
|
||||
|
|
|
@ -565,15 +565,16 @@ MQTTMessageTrigger::MQTTMessageTrigger(const std::string &topic) : topic_(topic)
|
|||
void MQTTMessageTrigger::set_qos(uint8_t qos) { this->qos_ = qos; }
|
||||
void MQTTMessageTrigger::set_payload(const std::string &payload) { this->payload_ = payload; }
|
||||
void MQTTMessageTrigger::setup() {
|
||||
global_mqtt_client->subscribe(this->topic_,
|
||||
[this](const std::string &topic, const std::string &payload) {
|
||||
if (this->payload_.has_value() && payload != *this->payload_) {
|
||||
return;
|
||||
}
|
||||
global_mqtt_client->subscribe(
|
||||
this->topic_,
|
||||
[this](const std::string &topic, const std::string &payload) {
|
||||
if (this->payload_.has_value() && payload != *this->payload_) {
|
||||
return;
|
||||
}
|
||||
|
||||
this->trigger(payload);
|
||||
},
|
||||
this->qos_);
|
||||
this->trigger(payload);
|
||||
},
|
||||
this->qos_);
|
||||
}
|
||||
void MQTTMessageTrigger::dump_config() {
|
||||
ESP_LOGCONFIG(TAG, "MQTT Message Trigger:");
|
||||
|
|
|
@ -7,18 +7,19 @@ namespace mqtt_subscribe {
|
|||
static const char *TAG = "mqtt_subscribe.sensor";
|
||||
|
||||
void MQTTSubscribeSensor::setup() {
|
||||
mqtt::global_mqtt_client->subscribe(this->topic_,
|
||||
[this](const std::string &topic, std::string payload) {
|
||||
auto val = parse_float(payload);
|
||||
if (!val.has_value()) {
|
||||
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
|
||||
this->publish_state(NAN);
|
||||
return;
|
||||
}
|
||||
mqtt::global_mqtt_client->subscribe(
|
||||
this->topic_,
|
||||
[this](const std::string &topic, std::string payload) {
|
||||
auto val = parse_float(payload);
|
||||
if (!val.has_value()) {
|
||||
ESP_LOGW(TAG, "Can't convert '%s' to number!", payload.c_str());
|
||||
this->publish_state(NAN);
|
||||
return;
|
||||
}
|
||||
|
||||
this->publish_state(*val);
|
||||
},
|
||||
this->qos_);
|
||||
this->publish_state(*val);
|
||||
},
|
||||
this->qos_);
|
||||
}
|
||||
|
||||
float MQTTSubscribeSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }
|
||||
|
|
|
@ -7,9 +7,9 @@ namespace mqtt_subscribe {
|
|||
static const char *TAG = "mqtt_subscribe.text_sensor";
|
||||
|
||||
void MQTTSubscribeTextSensor::setup() {
|
||||
this->parent_->subscribe(this->topic_,
|
||||
[this](const std::string &topic, std::string payload) { this->publish_state(payload); },
|
||||
this->qos_);
|
||||
this->parent_->subscribe(
|
||||
this->topic_, [this](const std::string &topic, std::string payload) { this->publish_state(payload); },
|
||||
this->qos_);
|
||||
}
|
||||
float MQTTSubscribeTextSensor::get_setup_priority() const { return setup_priority::AFTER_CONNECTION; }
|
||||
void MQTTSubscribeTextSensor::set_qos(uint8_t qos) { this->qos_ = qos; }
|
||||
|
|
|
@ -95,7 +95,7 @@ float clamp(float val, float min, float max);
|
|||
float lerp(float completion, float start, float end);
|
||||
|
||||
/// std::make_unique
|
||||
template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args &&... args) {
|
||||
template<typename T, typename... Args> std::unique_ptr<T> make_unique(Args &&...args) {
|
||||
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
|
||||
}
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ def run_format(args, queue, lock):
|
|||
"""Takes filenames out of queue and runs clang-tidy on them."""
|
||||
while True:
|
||||
path = queue.get()
|
||||
invocation = ['clang-format-7']
|
||||
invocation = ['clang-format-11']
|
||||
if args.inplace:
|
||||
invocation.append('-i')
|
||||
invocation.append(path)
|
||||
|
@ -69,12 +69,12 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
get_output('clang-format-7', '-version')
|
||||
get_output('clang-format-11', '-version')
|
||||
except:
|
||||
print("""
|
||||
Oops. It looks like clang-format is not installed.
|
||||
|
||||
Please check you can run "clang-format-7 -version" in your terminal and install
|
||||
Please check you can run "clang-format-11 -version" in your terminal and install
|
||||
clang-format (v7) if necessary.
|
||||
|
||||
Note you can also upload your code as a pull request on GitHub and see the CI check
|
||||
|
|
|
@ -30,7 +30,7 @@ else:
|
|||
def run_tidy(args, tmpdir, queue, lock, failed_files):
|
||||
while True:
|
||||
path = queue.get()
|
||||
invocation = ['clang-tidy-7', '-header-filter=^{}/.*'.format(re.escape(basepath))]
|
||||
invocation = ['clang-tidy-11', '-header-filter=^{}/.*'.format(re.escape(basepath))]
|
||||
if tmpdir is not None:
|
||||
invocation.append('-export-fixes')
|
||||
# Get a temporary file. We immediately close the handle so clang-tidy can
|
||||
|
@ -90,13 +90,13 @@ def main():
|
|||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
get_output('clang-tidy-7', '-version')
|
||||
get_output('clang-tidy-11', '-version')
|
||||
except:
|
||||
print("""
|
||||
Oops. It looks like clang-tidy is not installed.
|
||||
Oops. It looks like clang-tidy-11 is not installed.
|
||||
|
||||
Please check you can run "clang-tidy-7 -version" in your terminal and install
|
||||
clang-tidy (v7) if necessary.
|
||||
Please check you can run "clang-tidy-11 -version" in your terminal and install
|
||||
clang-tidy (v11) 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.
|
||||
|
@ -163,7 +163,7 @@ def main():
|
|||
if args.fix and failed_files:
|
||||
print('Applying fixes ...')
|
||||
try:
|
||||
subprocess.call(['clang-apply-replacements-7', tmpdir])
|
||||
subprocess.call(['clang-apply-replacements-11', tmpdir])
|
||||
except:
|
||||
print('Error applying fixes.\n', file=sys.stderr)
|
||||
raise
|
||||
|
|
Loading…
Reference in a new issue