Skip to content

Commit

Permalink
File filtering management with relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
nvuillam committed Sep 15, 2022
1 parent afcdcaa commit 6f25336
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,7 @@ def collect_files(self, all_files):
file_contains_regex=self.file_contains_regex,
files_sub_directory=self.files_sub_directory,
lint_all_other_linters_files=self.lint_all_other_linters_files,
workspace=self.workspace
)
self.files_number = len(self.files)
logging.debug(
Expand Down
1 change: 1 addition & 0 deletions megalinter/MegaLinter.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ def collect_files(self):
file_extensions=self.file_extensions,
ignored_files=ignored_files,
ignore_generated_files=self.ignore_generated_files,
workspace=self.workspace
)

logging.info(
Expand Down
8 changes: 5 additions & 3 deletions megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def filter_files(
file_contains_regex: Optional[Sequence[str]] = None,
files_sub_directory: Optional[str] = None,
lint_all_other_linters_files: bool = False,
workspace: Optional[str] = '',
prefix: Optional[str] = None,
) -> Sequence[str]:
file_extensions = set(file_extensions)
Expand All @@ -98,6 +99,7 @@ def filter_files(

for file in all_files:
file_with_prefix_and_sub_dir = os.path.normpath(file)
file_absolute = os.path.join(workspace, file_with_prefix_and_sub_dir)
file = file_with_prefix_and_sub_dir

if prefix or files_sub_directory:
Expand Down Expand Up @@ -142,16 +144,16 @@ def filter_files(
# Skip according to end of file name
if file_names_not_ends_with and file.endswith(tuple(file_names_not_ends_with)):
continue
# Skip according to file name regex
# Skip according to file content regex
if file_contains_regex and not file_contains(
file_with_prefix_and_sub_dir, file_contains_regex_object
file_absolute, file_contains_regex_object
):
continue
# Skip according to IGNORE_GENERATED_FILES
if (
ignore_generated_files is not None
and ignore_generated_files is True
and file_is_generated(file_with_prefix_and_sub_dir)
and file_is_generated(file_absolute)
):
continue

Expand Down

0 comments on commit 6f25336

Please sign in to comment.