Skip to content

Instantly share code, notes, and snippets.

@pfiaux

pfiaux/README.md Secret

Created August 25, 2023 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pfiaux/5b2d6a37831217816551ff74993caf48 to your computer and use it in GitHub Desktop.
Save pfiaux/5b2d6a37831217816551ff74993caf48 to your computer and use it in GitHub Desktop.
Megalinter V7 Compatibility with V6 Regex include/exclude patterns on relative paths

Reproducing MegaLinter Issue #2744

This helps reproduce the behavior mentioned in oxsecurity/megalinter#2744 which is not backwards compatible with V6.

Setting up a test image locally:

docker pull artifacts.open.ch/public-docker-virtual/oxsecurity/megalinter-ci_light:v7

docker run -it \
    --entrypoint bash \
    -v $PWD:/test \
    artifacts.open.ch/public-docker-virtual/oxsecurity/megalinter-ci_light:v7

Both shell scripts team1/test.sh and team2/test.sh have an issue detected by shellcheck. However only team 1 is included using the relative repo path: ^(team1/) The expected lint output is: 1 issue found in team1/test.sh.

Reproducing the changes in the image:

# Create a setup with 2 team folders each with a script (GIST wont allow folders)
mkdir -p /src/team1 /src/team2
pushd /src
git init
cp /test/test.sh /src/team1
cp /test/test.sh /src/team2
cp /test/mega-linter.yaml /src/
popd


# Current V7 behavior: all paths are absolute relative regex do not work:
DEFAULT_WORKSPACE="/src" MEGALINTER_CONFIG="/src/mega-linter.yaml" /entrypoint.sh

# Include change:
git apply /test/relativepath.patch

# With change to pass relative paths to the linters (which themselves should handle both relative and workspace/abs paths when filtering)
DEFAULT_WORKSPACE="/src" MEGALINTER_CONFIG="/src/mega-linter.yaml" /entrypoint.sh
VALIDATE_ALL_CODEBASE: false
APPLY_FIXES: none
FAIL_IF_MISSING_LINTER_IN_FLAVOR: true
LOG_LEVEL: DEBUG
PRINT_ALPACA: false
SHOW_ELAPSED_TIME: true
SHOW_SKIPPED_LINTERS: true
EXCLUDED_DIRECTORIES: []
MEGALINTER_FILES_TO_LINT:
- team1/test.sh
- team2/test.sh
REPORT_OUTPUT_FOLDER: none
CONFIG_REPORTER: false
EMAIL_REPORTER: false
FILEIO_REPORTER: false
FLAVOR_SUGGESTIONS: false
TAP_REPORTER: false
TEXT_REPORTER: false
UPDATED_SOURCES_REPORTER: false
ENABLE_LINTERS:
- BASH_SHELLCHECK
BASH_SHELLCHECK_FILTER_REGEX_INCLUDE: ^(team1/)
BASH_SHELLCHECK_FILTER_REGEX_EXCLUDE: ^(team2/)
diff --git a/megalinter/MegaLinter.py b/megalinter/MegaLinter.py
index 8bcb894d5e..261394bb0d 100644
--- a/megalinter/MegaLinter.py
+++ b/megalinter/MegaLinter.py
@@ -630,7 +630,7 @@ class Megalinter:
all_files = list()
for file_to_lint in files_to_lint:
if os.path.isfile(self.workspace + os.path.sep + file_to_lint):
- all_files += [self.workspace + os.path.sep + file_to_lint]
+ all_files += [file_to_lint]
else:
logging.warning(
"[File listing] Input file "
#!/usr/bin/env bash
set -o errexit
set -o pipefail
set -o nounset
echo "Linting the following lint will cause shellcheck to give a glob issue"
NAME="test name"
echo "Hello " $NAME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment