Skip to content

Commit

Permalink
Fix: Allow active_only_if_file_found to work in specified subdirector…
Browse files Browse the repository at this point in the history
…y (_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 <[email protected]>
Co-authored-by: Nicolas Vuillamy <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2024
1 parent dc9c553 commit ee5c1aa
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/descriptors/css_scss_lint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>
> 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.
>
Expand Down
2 changes: 1 addition & 1 deletion docs/descriptors/repository_semgrep.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/semgrep/semgrep/issues/9632> 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.

Expand Down
2 changes: 1 addition & 1 deletion docs/descriptors/xml_xmllint.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<br/>Ex: `-s --foo "bar"` | |
| XML_XMLLINT_COMMAND_REMOVE_ARGUMENTS | User custom arguments to remove from command line before calling the linter<br/>Ex: `-s --foo "bar"` | |
| XML_XMLLINT_FILTER_REGEX_INCLUDE | Custom regex including filter<br/>Ex: `(src\|lib)` | Include every file |
Expand Down
9 changes: 8 additions & 1 deletion megalinter/Linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ee5c1aa

Please sign in to comment.