diff --git a/CHANGELOG.md b/CHANGELOG.md index 47822053630..d800f67192d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l - Add Makefile linter within python flavor ([#1760](https://github.com/oxsecurity/megalinter/issues/1760)) - Set DEFAULT_WORKSPACE as git safe directory per default [#1766](https://github.com/oxsecurity/megalinter/issues/1766) - Improve documentation for TAP_REPORTER +- Fix: Properly match `files_sub_directory` as a prefix instead of partial string matching - Linter versions upgrades - [actionlint](https://rhysd.github.io/actionlint/) from 1.6.15 to **1.6.16** diff --git a/megalinter/Linter.py b/megalinter/Linter.py index 5cd3c31a09f..12059e99c9a 100644 --- a/megalinter/Linter.py +++ b/megalinter/Linter.py @@ -781,6 +781,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, + prefix=self.workspace, ) self.files_number = len(self.files) logging.debug( diff --git a/megalinter/utils.py b/megalinter/utils.py index 06e7933a4c7..9cd71dad3b4 100644 --- a/megalinter/utils.py +++ b/megalinter/utils.py @@ -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, + prefix: Optional[str] = None, ) -> Sequence[str]: file_extensions = set(file_extensions) filter_regex_include_object = ( @@ -114,7 +115,7 @@ def filter_files( if filter_regex_exclude_object and filter_regex_exclude_object.search(file): continue # Skip if file is not in defined files_sub_directory - if files_sub_directory and files_sub_directory not in file: + if files_sub_directory and not os.path.normpath(file).startswith(os.path.normpath(os.path.join(prefix or "", files_sub_directory) + os.path.sep)): continue # Skip according to file extension (only if lint_all_other_linter_files is false)