fbt: lint fixes (#2008)

* 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: あく <alleteam@gmail.com>
This commit is contained in:
hedger 2022-11-12 14:03:22 +04:00 committed by GitHub
parent 3c7a4eeaed
commit f9730bcafe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 33 additions and 24 deletions

View File

@ -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

View File

@ -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}",

View File

@ -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"),

View File

@ -2,8 +2,7 @@ Import("env")
env.Append(
LINT_SOURCES=[
"furi",
"furi/core",
Dir("."),
]
)

View File

@ -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"),

View File

@ -2,7 +2,7 @@ Import("env")
env.Append(
LINT_SOURCES=[
"lib/lfrfid",
Dir("."),
],
CPPPATH=[
"#/lib/lfrfid",

View File

@ -5,7 +5,7 @@ env.Append(
"#/lib/nfc",
],
SDK_HEADERS=[
File("#/lib/nfc/nfc_device.h"),
File("nfc_device.h"),
],
)

View File

@ -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]