Skip to content

Commit

Permalink
Fix FILTER_REGEX_EXCLUDE regression
Browse files Browse the repository at this point in the history
Fixes #2697
  • Loading branch information
nvuillam committed May 28, 2023
1 parent 352ab1d commit dd48bdb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-linter.yml file, or with `oxsecurity/megalinter:beta` docker image

- Secure PRE_COMMANDS and POST_COMMANDS by default
- Linter enhancements & fixes
- New variable **TERRAFORM_TFLINT_SECURED_ENV** with default value `true`. Set to `false` to allow `tflint --init` to access your env vars.

- Core
- Secure PRE_COMMANDS and POST_COMMANDS by default
- Can be disabled with **secured_env: false** in the command definition
- New variable **TERRAFORM_TFLINT_SECURED_ENV** with default value `true`. Set to `false` to allow `tflint --init` to access your env vars.
- Fix FILTER_REGEX_EXCLUDE when regex contains **^**

- Linter versions upgrades
- [checkstyle](https://checkstyle.sourceforge.io) from 10.11.0 to **10.12.0** on 2023-05-27
Expand Down
22 changes: 22 additions & 0 deletions megalinter/tests/test_megalinter/filters_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,28 @@ def test_filter_files_with_file_extensions(self):
sorted(filtered_files), sorted(expected), f"check {file_extensions}"
)


def test_filter_regex_exclude_single_level(self):
all_files = [
"index.html",
"target/index.html",
]
filtered_files = utils.filter_files(
all_files=all_files,
filter_regex_include=None,
filter_regex_exclude=["(^index.html)"],
file_names_regex=[],
file_extensions=["*"],
ignored_files=[],
ignore_generated_files=False,
)
self.assertListEqual(
sorted(filtered_files),
sorted(["target/index.html"]),
"check regex_exclude_multilevel",
)


def test_filter_regex_exclude_multilevel(self):
all_files = [
"should/be/excluded/descriptor-level/test.md",
Expand Down
4 changes: 2 additions & 2 deletions megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ def filter_files(
_, file_extension = os.path.splitext(base_file_name)
# Skip according to FILTER_REGEX_INCLUDE
if filter_regex_include_object and not filter_regex_include_object.search(
file_with_workspace
file
):
continue
# Skip according to FILTER_REGEX_EXCLUDE list
excluded_by_regex = False
for filter_regex_exclude_object in filter_regex_exclude_objects:
if filter_regex_exclude_object and filter_regex_exclude_object.search(
file_with_workspace
file
):
excluded_by_regex = True
break
Expand Down

0 comments on commit dd48bdb

Please sign in to comment.