diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b3580ebbf..17fc7353176 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,9 @@ Note: Can be used with `oxsecurity/megalinter@beta` in your GitHub Action mega-l - Change name of config file for powershell formatter to avoid collision with powershell linter config - Enhance find SARIF json in stdout output - Pass --show-context, --show-suggestions, and --no-must-find-files to CSpell for friendlier UX - by @Kurt-von-Laven in [#2271](https://github.com/oxsecurity/megalinter/issues/2271). + by @Kurt-von-Laven in [#2275](https://github.com/oxsecurity/megalinter/pull/2275). + - Only run npm-package-json-lint when package.json is present by @Kurt-von-Laven in + [#2280](https://github.com/oxsecurity/megalinter/pull/2280). - Documentation - Configure jsonschema documentation formatting (see [Descriptor schema](https://megalinter.io/latest/json-schemas/descriptor.html), [Configuration schema](https://megalinter.io/latest/json-schemas/configuration.html)), by @echoix in [#2270](https://github.com/oxsecurity/megalinter/pull/2270) diff --git a/megalinter/descriptors/json.megalinter-descriptor.yml b/megalinter/descriptors/json.megalinter-descriptor.yml index 32cc6ca6bc9..3b3021d88bf 100644 --- a/megalinter/descriptors/json.megalinter-descriptor.yml +++ b/megalinter/descriptors/json.megalinter-descriptor.yml @@ -233,6 +233,8 @@ linters: - salesforce file_names_regex: - "package\\.json" + active_only_if_file_found: + - "package.json" cli_lint_mode: project cli_executable: npmPkgJsonLint cli_config_arg_name: --configFile diff --git a/megalinter/flavor_factory.py b/megalinter/flavor_factory.py index 5e7e901123e..99fda5f1e2c 100644 --- a/megalinter/flavor_factory.py +++ b/megalinter/flavor_factory.py @@ -84,31 +84,31 @@ def check_active_linters_match_flavor(active_linters): missing_linters = [] for active_linter in active_linters: if active_linter.name not in flavor_linters: - missing_linters += [active_linter.name] active_linter.is_active = False - # Manage cases where linters are missing in flavor - if len(missing_linters) > 0: - # Do not warn/stop if missing linters are repository ones (mostly OX.security related) - if not are_all_repository_linters(missing_linters): - missing_linters_str = ",".join(missing_linters) - logging.warning( - f"MegaLinter flavor [{flavor}] does not contain linters {missing_linters_str}.\n" - "As they are not available in this docker image, they will not be processed\n" - "To solve this problem, please either: \n" - f"- use default flavor {ML_REPO}\n" - "- add ignored linters in DISABLE or DISABLE_LINTERS variables in your .mega-linter.yml config file " - "located in your root directory\n" - "- ignore this message by setting config variable FLAVOR_SUGGESTIONS to false" - ) - # Stop the process if user wanted so in case of missing linters - if config.get("FAIL_IF_MISSING_LINTER_IN_FLAVOR", "") == "true": - logging.error( - 'Missing linter and FAIL_IF_MISSING_LINTER_IN_FLAVOR has been set to "true": Stop run' - ) - sys.exit(84) - return False - # All good ! - return True + # Ignore linters that shouldn't trigger failure when missing. + if not active_linter.name.startswith("REPOSITORY"): + missing_linters.append(active_linter.name) + + if not missing_linters: + return True + + missing_linters_str = ",".join(missing_linters) + logging.warning( + f"MegaLinter flavor [{flavor}] does not contain linters {missing_linters_str}.\n" + "As they are not available in this Docker image, they will not be processed\n" + "To solve this problem, please either: \n" + f"- use default flavor {ML_REPO}\n" + "- add ignored linters in DISABLE or DISABLE_LINTERS variables in your .mega-linter.yml config file " + "located in your root directory\n" + "- ignore this message by setting config variable FLAVOR_SUGGESTIONS to false" + ) + # Stop the process if user wanted so in case of missing linters + if config.get("FAIL_IF_MISSING_LINTER_IN_FLAVOR", "") == "true": + logging.error( + 'Missing linter and FAIL_IF_MISSING_LINTER_IN_FLAVOR has been set to "true": Stop run' + ) + sys.exit(84) + return False # Compare active linters with available flavors to make suggestions to improve CI performances @@ -147,13 +147,3 @@ def get_megalinter_flavor_suggestions(active_linters): ) new_flavor_linters_names = map(lambda linter: linter.name, new_flavor_linters) return ["new", new_flavor_linters_names] - - -def are_all_repository_linters(linter_names: list[str]) -> bool: - if len(linter_names) == 0: - return False - result = True - for linter_name in linter_names: - if not linter_name.startswith("REPOSITORY"): - result = False - return result