diff --git a/CHANGELOG.md b/CHANGELOG.md index da1c86a9e11..e357afc038a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/megalinter/tests/test_megalinter/filters_test.py b/megalinter/tests/test_megalinter/filters_test.py index 845519cd033..16317c483b4 100644 --- a/megalinter/tests/test_megalinter/filters_test.py +++ b/megalinter/tests/test_megalinter/filters_test.py @@ -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", diff --git a/megalinter/utils.py b/megalinter/utils.py index 665f1f49d62..00c90312d67 100644 --- a/megalinter/utils.py +++ b/megalinter/utils.py @@ -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