Skip to content

Commit

Permalink
FBT: Don't lint JS packages (#4030)
Browse files Browse the repository at this point in the history
Co-authored-by: あく <[email protected]>
  • Loading branch information
Willy-JL and skotopes authored Dec 23, 2024
1 parent a02781b commit 33f1a16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 2 additions & 0 deletions firmware.scons
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ env = ENV.Clone(
TARGETS_ROOT=Dir("#/targets"),
LINT_SOURCES=[
Dir("applications"),
# Not C code
Dir("!applications/system/js_app/packages"),
],
LIBPATH=[
"${LIB_DIST_DIR}",
Expand Down
26 changes: 18 additions & 8 deletions scripts/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,25 @@ def init(self):
self.parser_format.set_defaults(func=self.format)

@staticmethod
def _filter_lint_directories(dirnames: list[str]):
def _filter_lint_directories(
dirpath: str, dirnames: list[str], excludes: tuple[str]
):
# Skipping 3rd-party code - usually resides in subfolder "lib"
if "lib" in dirnames:
dirnames.remove("lib")
# Skipping hidden folders
# Skipping hidden and excluded folders
for dirname in dirnames.copy():
if dirname.startswith("."):
dirnames.remove(dirname)
if os.path.join(dirpath, dirname).startswith(excludes):
dirnames.remove(dirname)

def _check_folders(self, folders: list):
def _check_folders(self, folders: list, excludes: tuple[str]):
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)
self._filter_lint_directories(dirpath, dirnames, excludes)

for dirname in dirnames:
if not pattern.match(dirname):
Expand All @@ -61,11 +65,11 @@ def _check_folders(self, folders: list):
"Folders are not renamed automatically, please fix it by yourself"
)

def _find_sources(self, folders: list):
def _find_sources(self, folders: list, excludes: tuple[str]):
output = []
for folder in folders:
for dirpath, dirnames, filenames in os.walk(folder):
self._filter_lint_directories(dirnames)
self._filter_lint_directories(dirpath, dirnames, excludes)

for filename in filenames:
ext = os.path.splitext(filename.lower())[1]
Expand Down Expand Up @@ -168,14 +172,20 @@ def _apply_file_permissions(self, sources: list, dry_run: bool = False):

def _perform(self, dry_run: bool):
result = 0
sources = self._find_sources(self.args.input)
excludes = []
for folder in self.args.input.copy():
if folder.startswith("!"):
excludes.append(folder.removeprefix("!"))
self.args.input.remove(folder)
excludes = tuple(excludes)
sources = self._find_sources(self.args.input, excludes)
if not self._format_sources(sources, dry_run=dry_run):
result |= 0b001
if not self._apply_file_naming_convention(sources, dry_run=dry_run):
result |= 0b010
if not self._apply_file_permissions(sources, dry_run=dry_run):
result |= 0b100
self._check_folders(self.args.input)
self._check_folders(self.args.input, excludes)
return result

def check(self):
Expand Down

0 comments on commit 33f1a16

Please sign in to comment.