From f9730bcafeafec8afbe82fa676133b413a6bbae0 Mon Sep 17 00:00:00 2001 From: hedger Date: Sat, 12 Nov 2022 14:03:22 +0400 Subject: [PATCH] fbt: lint fixes (#2008) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lint: exclude "lib" subfolder from naming checks; fbt: moved LINT_SOURCES from literal strings to Dir() nodes * lint: also exclude hidden directories Co-authored-by: あく --- SConstruct | 4 ++-- firmware.scons | 2 +- firmware/SConscript | 2 +- furi/SConscript | 3 +-- lib/SConscript | 26 +++++++++++++------------- lib/lfrfid/SConscript | 2 +- lib/nfc/SConscript | 2 +- scripts/lint.py | 16 +++++++++++++--- 8 files changed, 33 insertions(+), 24 deletions(-) diff --git a/SConstruct b/SConstruct index 34ff80bc9..474175c14 100644 --- a/SConstruct +++ b/SConstruct @@ -241,13 +241,13 @@ distenv.PhonyTarget( distenv.PhonyTarget( "lint", "${PYTHON3} ${FBT_SCRIPT_DIR}/lint.py check ${LINT_SOURCES}", - LINT_SOURCES=firmware_env["LINT_SOURCES"], + LINT_SOURCES=[n.srcnode() for n in firmware_env["LINT_SOURCES"]], ) distenv.PhonyTarget( "format", "${PYTHON3} ${FBT_SCRIPT_DIR}/lint.py format ${LINT_SOURCES}", - LINT_SOURCES=firmware_env["LINT_SOURCES"], + LINT_SOURCES=[n.srcnode() for n in firmware_env["LINT_SOURCES"]], ) # PY_LINT_SOURCES contains recursively-built modules' SConscript files + application manifests diff --git a/firmware.scons b/firmware.scons index da5caba53..d674bf160 100644 --- a/firmware.scons +++ b/firmware.scons @@ -22,7 +22,7 @@ env = ENV.Clone( FW_FLAVOR=fw_build_meta["flavor"], LIB_DIST_DIR=fw_build_meta["build_dir"].Dir("lib"), LINT_SOURCES=[ - "applications", + Dir("applications"), ], LIBPATH=[ "${LIB_DIST_DIR}", diff --git a/firmware/SConscript b/firmware/SConscript index 19dde2e4c..a16f14e65 100644 --- a/firmware/SConscript +++ b/firmware/SConscript @@ -1,7 +1,7 @@ Import("env") env.Append( - LINT_SOURCES=["firmware"], + LINT_SOURCES=[Dir(".")], SDK_HEADERS=[ *env.GlobRecursive("*.h", "targets/furi_hal_include", "*_i.h"), *env.GlobRecursive("*.h", "targets/f${TARGET_HW}/furi_hal", "*_i.h"), diff --git a/furi/SConscript b/furi/SConscript index f95ef13f9..8f8caeb87 100644 --- a/furi/SConscript +++ b/furi/SConscript @@ -2,8 +2,7 @@ Import("env") env.Append( LINT_SOURCES=[ - "furi", - "furi/core", + Dir("."), ] ) diff --git a/lib/SConscript b/lib/SConscript index 60ffabfa9..abede5f33 100644 --- a/lib/SConscript +++ b/lib/SConscript @@ -2,19 +2,19 @@ Import("env") env.Append( LINT_SOURCES=[ - "lib/app-scened-template", - "lib/digital_signal", - "lib/drivers", - "lib/flipper_format", - "lib/infrared", - "lib/nfc", - "lib/one_wire", - "lib/ST25RFAL002", - "lib/subghz", - "lib/toolbox", - "lib/u8g2", - "lib/update_util", - "lib/print", + Dir("app-scened-template"), + Dir("digital_signal"), + Dir("drivers"), + Dir("flipper_format"), + Dir("infrared"), + Dir("nfc"), + Dir("one_wire"), + Dir("ST25RFAL002"), + Dir("subghz"), + Dir("toolbox"), + Dir("u8g2"), + Dir("update_util"), + Dir("print"), ], SDK_HEADERS=[ File("one_wire/one_wire_host_timing.h"), diff --git a/lib/lfrfid/SConscript b/lib/lfrfid/SConscript index 69ea9d3c1..f9431ca75 100644 --- a/lib/lfrfid/SConscript +++ b/lib/lfrfid/SConscript @@ -2,7 +2,7 @@ Import("env") env.Append( LINT_SOURCES=[ - "lib/lfrfid", + Dir("."), ], CPPPATH=[ "#/lib/lfrfid", diff --git a/lib/nfc/SConscript b/lib/nfc/SConscript index c6b70a677..b086298de 100644 --- a/lib/nfc/SConscript +++ b/lib/nfc/SConscript @@ -5,7 +5,7 @@ env.Append( "#/lib/nfc", ], SDK_HEADERS=[ - File("#/lib/nfc/nfc_device.h"), + File("nfc_device.h"), ], ) diff --git a/scripts/lint.py b/scripts/lint.py index c178c8763..58f2d69f5 100755 --- a/scripts/lint.py +++ b/scripts/lint.py @@ -35,11 +35,23 @@ class Main(App): ) self.parser_format.set_defaults(func=self.format) + @staticmethod + def _filter_lint_directories(dirnames: list[str]): + # Skipping 3rd-party code - usually resides in subfolder "lib" + if "lib" in dirnames: + dirnames.remove("lib") + # Skipping hidden folders + for dirname in dirnames.copy(): + if dirname.startswith("."): + dirnames.remove(dirname) + def _check_folders(self, folders: list): show_message = False pattern = re.compile(SOURCE_CODE_DIR_PATTERN) for folder in folders: for dirpath, dirnames, filenames in os.walk(folder): + self._filter_lint_directories(dirnames) + for dirname in dirnames: if not pattern.match(dirname): to_fix = os.path.join(dirpath, dirname) @@ -54,9 +66,7 @@ class Main(App): output = [] for folder in folders: for dirpath, dirnames, filenames in os.walk(folder): - # Skipping 3rd-party code - usually resides in subfolder "lib" - if "lib" in dirnames: - dirnames.remove("lib") + self._filter_lint_directories(dirnames) for filename in filenames: ext = os.path.splitext(filename.lower())[1]