Skip to content

Commit

Permalink
Manage v6 retrocompatiblity with FILTER_REGEX_INCLUDE and FILTER_REGE…
Browse files Browse the repository at this point in the history
…X_EXCLUDE expression (#2698)

* [automation] Auto-update linters version, help and documentation

* [MegaLinter] Apply linters fixes

* TERRAFORM_TFLINT_SECURED_ENV management

* [MegaLinter] Apply linters fixes

* Fix FILTER_REGEX_EXCLUDE regression

Fixes #2697

* [MegaLinter] Apply linters fixes

* tflint test class

* Build doc

* Retrocompatiblity of FILTER_REGEX_EXCLUDE with v6

* label

---------

Co-authored-by: nvuillam <[email protected]>
  • Loading branch information
nvuillam and nvuillam authored May 28, 2023
1 parent 8f6a79d commit ac577a9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 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.
- 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

0 comments on commit ac577a9

Please sign in to comment.