From da403ce7834adfca0a07fe098e97a76e9b0d05dd Mon Sep 17 00:00:00 2001 From: nvuillam Date: Tue, 23 Apr 2024 19:36:32 +0200 Subject: [PATCH 1/2] Implement fallback in case git diff does not work with merge-base --- CHANGELOG.md | 1 + megalinter/MegaLinter.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ab2317648f..e8fa2c609cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l - Reporters - Fixes + - Implement fallback in case git diff does not work with merge-base - Doc diff --git a/megalinter/MegaLinter.py b/megalinter/MegaLinter.py index 93e5e9ed0f8..15eaf421acb 100644 --- a/megalinter/MegaLinter.py +++ b/megalinter/MegaLinter.py @@ -776,7 +776,16 @@ def list_files_git_diff(self): # Try to fetch default_branch from origin, because it isn't cached locally. repo.git.fetch("origin", f"{remote_ref}:{local_ref}") # Make git diff to list files (and exclude symlinks) - diff = repo.git.diff(f"{default_branch_remote}...", name_only=True) + try: + # Use optimized way from https://github.com/oxsecurity/megalinter/pull/3472 + diff = repo.git.diff(f"{default_branch_remote}...", name_only=True) + except Exception as e7: + # Use previous way as fallback + logging.warning("Git diff error: " + str(e7)) + logging.warning("You might need to add check-depth: 0 or equivalent to access merge-base") + logging.warning("See https://github.com/oxsecurity/megalinter/pull/3472") + logging.warning("Using fallback without merge-base...") + diff = repo.git.diff(default_branch_remote, name_only=True) logging.info(f"Modified files:\n{diff}") all_files = list() for diff_line in diff.splitlines(): From 987785fca1d69d6a4b1e788cd26d0b227b3ce330 Mon Sep 17 00:00:00 2001 From: nvuillam Date: Tue, 23 Apr 2024 17:43:35 +0000 Subject: [PATCH 2/2] [MegaLinter] Apply linters fixes --- CHANGELOG.md | 38 +++++++++++++++---------------- docs/descriptors/css_scss_lint.md | 2 +- docs/descriptors/xml_xmllint.md | 2 +- megalinter/MegaLinter.py | 6 +++-- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8fa2c609cc..824d8d1dcc1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,45 +31,45 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l ## [v7.11.0] - 2024-04-23 - Core - - Allow to override the number of parallel cores used, with variable **PARALLEL_PROCESS_NUMBER**, by @nvuillam in https://github.com/oxsecurity/megalinter/pull/3428 + - Allow to override the number of parallel cores used, with variable **PARALLEL_PROCESS_NUMBER**, by @nvuillam in - Upgrade base python image from 3.12.2-alpine3.19 to 3.12.3-alpine3.19 - - Upgrade PHP 8.1 to 8.3 by @llaville in https://github.com/oxsecurity/megalinter/pull/3464 - - Add descriptor pre / post commands, by @bdovaz in https://github.com/oxsecurity/megalinter/pull/3468 - - Allow merge lists with **EXTENDS**, by @bdovaz in https://github.com/oxsecurity/megalinter/pull/3469 + - Upgrade PHP 8.1 to 8.3 by @llaville in + - Add descriptor pre / post commands, by @bdovaz in + - Allow merge lists with **EXTENDS**, by @bdovaz in - Media - New linters - - Add Kotlin detekt linter, by @enciyo in https://github.com/oxsecurity/megalinter/pull/3408 + - Add Kotlin detekt linter, by @enciyo in - Reporters - - Add ruff sarif support, by @Skitionek in https://github.com/oxsecurity/megalinter/pull/3486 + - Add ruff sarif support, by @Skitionek in - Fixes - Fix listing of modified files, by @vkucera in . Fixes . - - Fix conflict between prettier and yamllint about spaces, by @apeyrat in https://github.com/oxsecurity/megalinter/pull/3426 - - Ensure [trufflehog](https://github.com/trufflesecurity/trufflehog) does not auto-update itself, by @wandering-tales in https://github.com/oxsecurity/megalinter/pull/3430 - - Salesforce linters: use sf + default Flow Scanner rules, by @nvuillam in https://github.com/oxsecurity/megalinter/pull/3435 + - Fix conflict between prettier and yamllint about spaces, by @apeyrat in + - Ensure [trufflehog](https://github.com/trufflesecurity/trufflehog) does not auto-update itself, by @wandering-tales in + - Salesforce linters: use sf + default Flow Scanner rules, by @nvuillam in - Disable JSON_ESLINT_PLUGIN_JSONC until is fixed - Upgrade tar in mega-linter-runner - secretlint: remove default `.secretlintignore` that was never used but `.gitignore` is used instead. Fixes [#3328](https://github.com/oxsecurity/megalinter/issues/3328) - - Add jpeg, xlsx to .gitleaks.toml, by @rasa in https://github.com/oxsecurity/megalinter/pull/3434 - - Fix Json Schema, by @nvuillam in https://github.com/oxsecurity/megalinter/pull/3470 - - Remove `TEMPLATES/.secretlintignore`, by @pjungermann in https://github.com/oxsecurity/megalinter/pull/3476 + - Add jpeg, xlsx to .gitleaks.toml, by @rasa in + - Fix Json Schema, by @nvuillam in + - Remove `TEMPLATES/.secretlintignore`, by @pjungermann in - Doc - - Update R2DevOps logo, by @nvuillam in https://github.com/oxsecurity/megalinter/pull/3436 - - Update [Roslynator](https://github.com/dotnet/roslynator) repo url and logo, by @TommyE123 in https://github.com/oxsecurity/megalinter/pull/3444 - - Fix clang-format documentation links to point to the correct version. Fixes [#3452](https://github.com/oxsecurity/megalinter/issues/3452), by @daltonv in https://github.com/oxsecurity/megalinter/pull/3453 - - Add copy to clipboard button in code block (documentation), by @nikkii86 in https://github.com/oxsecurity/megalinter/pull/3491 + - Update R2DevOps logo, by @nvuillam in + - Update [Roslynator](https://github.com/dotnet/roslynator) repo url and logo, by @TommyE123 in + - Fix clang-format documentation links to point to the correct version. Fixes [#3452](https://github.com/oxsecurity/megalinter/issues/3452), by @daltonv in + - Add copy to clipboard button in code block (documentation), by @nikkii86 in - Flavors - - Add C & C++ linters in Python flavor by @nvuillam in https://github.com/oxsecurity/megalinter/pull/3456 + - Add C & C++ linters in Python flavor by @nvuillam in - CI - Make SPELL_LYCHEE non blocking for internal CI jobs - - Remove old unused automerge workflows by @echoix in https://github.com/oxsecurity/megalinter/pull/3432 - - Add consistent python3/python handling at build.sh, by @pjungermann in https://github.com/oxsecurity/megalinter/pull/3475 + - Remove old unused automerge workflows by @echoix in + - Add consistent python3/python handling at build.sh, by @pjungermann in - Linter versions upgrades - [ansible-lint](https://ansible-lint.readthedocs.io/) from 24.2.0 to **24.2.2** diff --git a/docs/descriptors/css_scss_lint.md b/docs/descriptors/css_scss_lint.md index 22edc35b992..1bfa8e26a4f 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/xml_xmllint.md b/docs/descriptors/xml_xmllint.md index 7b21e39f980..1911062a6b5 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/MegaLinter.py b/megalinter/MegaLinter.py index 15eaf421acb..76d1f505e93 100644 --- a/megalinter/MegaLinter.py +++ b/megalinter/MegaLinter.py @@ -776,13 +776,15 @@ def list_files_git_diff(self): # Try to fetch default_branch from origin, because it isn't cached locally. repo.git.fetch("origin", f"{remote_ref}:{local_ref}") # Make git diff to list files (and exclude symlinks) - try: + try: # Use optimized way from https://github.com/oxsecurity/megalinter/pull/3472 diff = repo.git.diff(f"{default_branch_remote}...", name_only=True) except Exception as e7: # Use previous way as fallback logging.warning("Git diff error: " + str(e7)) - logging.warning("You might need to add check-depth: 0 or equivalent to access merge-base") + logging.warning( + "You might need to add check-depth: 0 or equivalent to access merge-base" + ) logging.warning("See https://github.com/oxsecurity/megalinter/pull/3472") logging.warning("Using fallback without merge-base...") diff = repo.git.diff(default_branch_remote, name_only=True)