From 422754ed63ac82072a69d5fb6146d3399d4bac84 Mon Sep 17 00:00:00 2001 From: Otto Winter Date: Fri, 24 May 2019 17:20:06 +0200 Subject: [PATCH] Lint --- esphome/components/deep_sleep/deep_sleep_component.cpp | 3 ++- script/clang-format | 4 ++-- script/clang-tidy | 4 ++-- script/helpers.py | 10 ++++++++++ script/lint-python | 8 +++++--- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/esphome/components/deep_sleep/deep_sleep_component.cpp b/esphome/components/deep_sleep/deep_sleep_component.cpp index 5f6aaf24cd..217c0cbf0d 100644 --- a/esphome/components/deep_sleep/deep_sleep_component.cpp +++ b/esphome/components/deep_sleep/deep_sleep_component.cpp @@ -19,7 +19,8 @@ void DeepSleepComponent::setup() { void DeepSleepComponent::dump_config() { ESP_LOGCONFIG(TAG, "Setting up Deep Sleep..."); if (this->sleep_duration_.has_value()) { - ESP_LOGCONFIG(TAG, " Sleep Duration: %u ms", *this->sleep_duration_ / 1000); + uint32_t duration = *this->sleep_duration_ / 1000; + ESP_LOGCONFIG(TAG, " Sleep Duration: %u ms", duration); } if (this->run_duration_.has_value()) { ESP_LOGCONFIG(TAG, " Run Duration: %u ms", *this->run_duration_); diff --git a/script/clang-format b/script/clang-format index d5792c783e..89a5acd746 100755 --- a/script/clang-format +++ b/script/clang-format @@ -13,7 +13,7 @@ import threading import click sys.path.append(os.path.dirname(__file__)) -from helpers import basepath, get_output, walk_files, filter_changed +from helpers import basepath, get_output, git_ls_files, filter_changed is_py2 = sys.version[0] == '2' @@ -83,7 +83,7 @@ def main(): return 1 files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.cpp', '.h', '.tcc') ext = os.path.splitext(path)[1] if ext in filetypes: diff --git a/script/clang-tidy b/script/clang-tidy index 124008a873..39df87df22 100755 --- a/script/clang-tidy +++ b/script/clang-tidy @@ -18,7 +18,7 @@ import threading sys.path.append(os.path.dirname(__file__)) from helpers import basepath, shlex_quote, get_output, build_compile_commands, \ - build_all_include, temp_header_file, walk_files, filter_changed + build_all_include, temp_header_file, git_ls_files, filter_changed is_py2 = sys.version[0] == '2' @@ -100,7 +100,7 @@ def main(): build_compile_commands() files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.cpp',) ext = os.path.splitext(path)[1] if ext in filetypes: diff --git a/script/helpers.py b/script/helpers.py index 8b37dce570..243dfde49e 100644 --- a/script/helpers.py +++ b/script/helpers.py @@ -126,3 +126,13 @@ def filter_changed(files): for c in files: print(" {}".format(c)) return files + + +def git_ls_files(): + command = ['git', 'ls-files', '-s'] + proc = subprocess.Popen(command, stdout=subprocess.PIPE) + output, err = proc.communicate() + lines = [x.split() for x in output.decode('utf-8').splitlines()] + return { + s[3].strip(): int(s[0]) for s in lines + } diff --git a/script/lint-python b/script/lint-python index cb702bf362..415efa0ebf 100755 --- a/script/lint-python +++ b/script/lint-python @@ -9,7 +9,7 @@ import re import sys sys.path.append(os.path.dirname(__file__)) -from helpers import basepath, get_output, walk_files, filter_changed +from helpers import get_output, git_ls_files, filter_changed def main(): @@ -21,10 +21,10 @@ def main(): args = parser.parse_args() files = [] - for path in walk_files(basepath): + for path in git_ls_files(): filetypes = ('.py',) ext = os.path.splitext(path)[1] - if ext in filetypes: + if ext in filetypes and path.startswith('esphome'): path = os.path.relpath(path, os.getcwd()) files.append(path) # Match against re @@ -35,6 +35,8 @@ def main(): files = filter_changed(files) files.sort() + if not files: + sys.exit(0) errors = collections.defaultdict(list) cmd = ['flake8'] + files