Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Match files_sub_directory as a prefix #1765

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
1 change: 1 addition & 0 deletions megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion 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,
prefix: Optional[str] = None,
) -> Sequence[str]:
file_extensions = set(file_extensions)
filter_regex_include_object = (
Expand Down Expand Up @@ -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)
Expand Down