Skip to content

Commit

Permalink
Fix: Match files_sub_directory as a prefix
Browse files Browse the repository at this point in the history
Properly match `files_sub_directory` as a prefix instead of partial string matching.

Before

- If directory named "files_sub_directory" exists then all files
  matching "files_sub_directory" are selected. For example if
  files_sub_directory is set to "dir" and dir exists under the workspace
  directory then "mode/direct/file.yml" and "new_directory/f.yml" will
  be selected

After

- If directory named "files_sub_directory" exists then all files
  which names start with "files_sub_directory" are selected. For example if
  files_sub_directory is set to "dir" (or "./dir" or "dir/" or "./dir/")
  and dir exists under the workspace directory then "dir/file.yml" will be
  selected but not "new_directory/f.yml" and not "some/dir/f.yml"
  • Loading branch information
giner committed Aug 19, 2022
1 parent b5b7741 commit fb6ff05
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l
- Fix version in URL in logs produced by reporters
- Improve documentation for TAP_REPORTER
- Fix flavors suggestions to ignore linters not relevant for such flavor ([#1746](https://github.com/oxsecurity/megalinter/issues/1746))
- Fix: Properly match `files_sub_directory` as a prefix instead of partial string matching

- Linter versions upgrades
- [eslint-plugin-jsonc](https://ota-meshi.github.io/eslint-plugin-jsonc/) from 2.3.1 to **2.4.0** on 2022-08-16
Expand Down
2 changes: 1 addition & 1 deletion megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,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.abspath(file).startswith(os.path.abspath(files_sub_directory) + os.path.sep):
continue

# Skip according to file extension (only if lint_all_other_linter_files is false)
Expand Down

0 comments on commit fb6ff05

Please sign in to comment.