From ee5c1aa2e4fb4a26d57023cf6bb19c8193d6ab8e Mon Sep 17 00:00:00 2001 From: Timothy Earley Date: Sat, 27 Jan 2024 13:13:06 +0100 Subject: [PATCH] Fix: Allow active_only_if_file_found to work in specified subdirectory (_DIRECTORY) (#3323) * fix: allow active_only_if_file_found to work in specified subdirectory (_DIRECTORY) Fixes #2873 This includes a new place when searching for active only if files. The other existing places are not affected. * run build * fix python code style, reduce diff --------- Co-authored-by: Timothy Earley Co-authored-by: Nicolas Vuillamy --- CHANGELOG.md | 1 + docs/descriptors/css_scss_lint.md | 2 +- docs/descriptors/repository_semgrep.md | 2 +- docs/descriptors/xml_xmllint.md | 2 +- megalinter/Linter.py | 9 ++++++++- .../schemas/megalinter-descriptor.jsonschema.json | 2 +- 6 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49f1b45d444..3ed68bc5f15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l - New linters - Fixes + - Allow active_only_if_file_found to work in specified subdirectory (_DIRECTORY), fixes [#2873](https://github.com/oxsecurity/megalinter/issues/2873) - Activate CI servers reporters only if we find a related default env variable - Doc diff --git a/docs/descriptors/css_scss_lint.md b/docs/descriptors/css_scss_lint.md index 5280481e188..c411ca85f35 100644 --- a/docs/descriptors/css_scss_lint.md +++ b/docs/descriptors/css_scss_lint.md @@ -15,7 +15,7 @@ description: How to use scss-lint (configure, ignore files, ignore errors, help > This linter has been deprecated. > -> +> https://github.com/sds/scss-lint#notice-consider-other-tools-before-adopting-scss-lint > > You should disable scss-lint by adding it in DISABLE_LINTERS property. > diff --git a/docs/descriptors/repository_semgrep.md b/docs/descriptors/repository_semgrep.md index 703772666ce..cea32495659 100644 --- a/docs/descriptors/repository_semgrep.md +++ b/docs/descriptors/repository_semgrep.md @@ -13,7 +13,7 @@ description: How to use semgrep (configure, ignore files, ignore errors, help & [![GitHub stars](https://img.shields.io/github/stars/returntocorp/semgrep?cacheSeconds=3600)](https://github.com/returntocorp/semgrep) ![sarif](https://shields.io/badge/-SARIF-orange) [![GitHub release (latest SemVer)](https://img.shields.io/github/v/release/returntocorp/semgrep?sort=semver)](https://github.com/returntocorp/semgrep/releases) [![GitHub last commit](https://img.shields.io/github/last-commit/returntocorp/semgrep)](https://github.com/returntocorp/semgrep/commits) [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/returntocorp/semgrep)](https://github.com/returntocorp/semgrep/graphs/commit-activity/) [![GitHub contributors](https://img.shields.io/github/contributors/returntocorp/semgrep)](https://github.com/returntocorp/semgrep/graphs/contributors/) -**Disabled until is solved** +**Disabled until https://github.com/semgrep/semgrep/issues/9632 is solved** To use SemGrep in MegaLinter you must define a list of rulesets to use. diff --git a/docs/descriptors/xml_xmllint.md b/docs/descriptors/xml_xmllint.md index ccdfcd71b5b..20dfe40766e 100644 --- a/docs/descriptors/xml_xmllint.md +++ b/docs/descriptors/xml_xmllint.md @@ -25,7 +25,7 @@ To apply file formatting you must set `XML_XMLLINT_CLI_LINT_MODE: file` and `XML | Variable | Description | Default value | |-----------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------| | XML_XMLLINT_AUTOFORMAT | If set to `true`, it will reformat and reindent the output | `false` | -| XML_XMLLINT_INDENT | The number of indentation spaces when `XML_XMLLINT_AUTOFORMAT` is `true` | `` | +| XML_XMLLINT_INDENT | The number of indentation spaces when `XML_XMLLINT_AUTOFORMAT` is `true` | ` ` | | XML_XMLLINT_ARGUMENTS | User custom arguments to add in linter CLI call
Ex: `-s --foo "bar"` | | | XML_XMLLINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter
Ex: `-s --foo "bar"` | | | XML_XMLLINT_FILTER_REGEX_INCLUDE | Custom regex including filter
Ex: `(src\|lib)` | Include every file | diff --git a/megalinter/Linter.py b/megalinter/Linter.py index 2755bc9d585..5029d5ef0cc 100644 --- a/megalinter/Linter.py +++ b/megalinter/Linter.py @@ -353,13 +353,20 @@ def __init__(self, params=None, linter_config=None): file_to_check, prop = file_to_check.split(":") if os.path.isfile(f"{self.workspace}{os.path.sep}{file_to_check}"): found_file = f"{self.workspace}{os.path.sep}{file_to_check}" - if os.path.isfile( + elif os.path.isfile( f"{self.workspace}{os.path.sep}{self.linter_rules_path}{os.path.sep}{file_to_check}" ): found_file = ( f"{self.workspace}{os.path.sep}{self.linter_rules_path}" + f"{os.path.sep}{file_to_check}" ) + elif os.path.isfile( + f"{self.workspace}{os.path.sep}{self.files_sub_directory}{os.path.sep}{file_to_check}" + ): + found_file = ( + f"{self.workspace}{os.path.sep}{self.files_sub_directory}" + + f"{os.path.sep}{file_to_check}" + ) # filename case if found_file is not None and prop is None: is_found = True diff --git a/megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json b/megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json index 3428b884572..8bff33ce855 100644 --- a/megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json +++ b/megalinter/descriptors/schemas/megalinter-descriptor.jsonschema.json @@ -67,7 +67,7 @@ "properties": { "active_only_if_file_found": { "$id": "#/properties/active_only_if_file_found", - "description": "Names of the config files to be found (at least one), else descriptor will be deactivated", + "description": "Names of the config files to be found (at least one), else descriptor will be deactivated. Search in workspace, linter rules path, and files_sub_directory", "examples": [ [ ".editorconfig",