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

Manage v6 retrocompatiblity with FILTER_REGEX_INCLUDE and FILTER_REGEX_EXCLUDE expression #2698

Merged
merged 13 commits into from
May 28, 2023
Merged
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.
- Manage v6 retrocompatibility with FILTER_REGEX_INCLUDE and FILTER_REGEX_EXCLUDE expression

- Linter versions upgrades
- [checkstyle](https://checkstyle.sourceforge.io) from 10.11.0 to **10.12.0** on 2023-05-27
Expand Down
20 changes: 20 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,26 @@ 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
12 changes: 8 additions & 4 deletions megalinter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,19 @@ def filter_files(
base_file_name = os.path.basename(file)
_, 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
if filter_regex_include_object and (
not filter_regex_include_object.search(file)
# Compatibility with v6 regexes
and not filter_regex_include_object.search(file_with_workspace)
):
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
if filter_regex_exclude_object and (
filter_regex_exclude_object.search(file)
# Compatibility with v6 regexes
or filter_regex_exclude_object.search(file_with_workspace)
):
excluded_by_regex = True
break
Expand Down