From daadd98d821bff26548d07978f588a2ad5409716 Mon Sep 17 00:00:00 2001 From: Niel Markwick Date: Thu, 24 Oct 2024 15:39:40 +0200 Subject: [PATCH] feat: Add JAVA_COMMAND_ARGS support Fixes #6281 --- README.md | 1 + lib/functions/linterCommands.sh | 8 +++++++- lib/globals/linterRules.sh | 2 ++ test/lib/linterCommandsTest.sh | 3 +++ 4 files changed, 13 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 20a4a062..95d60cb0 100644 --- a/README.md +++ b/README.md @@ -283,6 +283,7 @@ You can configure Super-linter using the following environment variables: | **IGNORE_GENERATED_FILES** | `false` | If set to `true`, super-linter will ignore all the files with `@generated` marker but without `@not-generated` marker. Jscpd and Checkov ignore this variable. Use their include and ignore features to select or ignore the files to lint. | | **IGNORE_GITIGNORED_FILES** | `false` | If set to `true`, super-linter will ignore all the files that are ignored by Git. Checkov ignores this variable. Use its include and ignore features to select or ignore the files to lint. | | **JAVA_FILE_NAME** | `sun_checks.xml` | Filename for [Checkstyle configuration](https://checkstyle.sourceforge.io/config.html). Checkstyle embeds several configuration files, such as `sun_checks.xml`, `google_checks.xml` that you can use without providing your own configuration file. | +| **JAVA_COMMAND_ARGS** | `null` | Additional Java JRE arguments passed to the checkstyle linter that can be used to specify additional configuration parameters via Java properties, such as [Suppression Filter files](https://checkstyle.org/filters/suppressionfilter.html), for example: `-Dorg.checkstyle.sun.suppressionfilter.config=path/to/suppressions.xml` | | **JAVASCRIPT_ES_CONFIG_FILE** | `.eslintrc.yml` | Filename for [ESLint configuration](https://eslint.org/docs/user-guide/configuring#configuration-file-formats) (ex: `.eslintrc.yml`, `.eslintrc.json`) | | **JSCPD_CONFIG_FILE** | `.jscpd.json` | Filename for JSCPD configuration | | **KUBERNETES_KUBECONFORM_OPTIONS** | `null` | Additional arguments to pass to the command-line when running **Kubernetes Kubeconform** (Example: --ignore-missing-schemas) | diff --git a/lib/functions/linterCommands.sh b/lib/functions/linterCommands.sh index 4c659c80..ff690bca 100755 --- a/lib/functions/linterCommands.sh +++ b/lib/functions/linterCommands.sh @@ -86,7 +86,13 @@ LINTER_COMMANDS_ARRAY_GRAPHQL_PRETTIER=("${PRETTIER_COMMAND[@]}") LINTER_COMMANDS_ARRAY_GROOVY=(npm-groovy-lint -c "${GROOVY_LINTER_RULES}" --failon warning --no-insight) LINTER_COMMANDS_ARRAY_HTML=(htmlhint --config "${HTML_LINTER_RULES}") LINTER_COMMANDS_ARRAY_HTML_PRETTIER=("${PRETTIER_COMMAND[@]}") -LINTER_COMMANDS_ARRAY_JAVA=(java -jar /usr/bin/checkstyle -c "${JAVA_LINTER_RULES}") +# Java checkstyle linter needs additional args passed _before_ the -jar arg +LINTER_COMMANDS_ARRAY_JAVA=(java) +if [ "${JAVA_COMMAND_ARGS}" != "null" ] && [ -n "${JAVA_COMMAND_ARGS}" ]; then + export JAVA_COMMAND_ARGS + AddOptionsToCommand "LINTER_COMMANDS_ARRAY_JAVA" "${JAVA_COMMAND_ARGS}" +fi +LINTER_COMMANDS_ARRAY_JAVA+=(-jar /usr/bin/checkstyle -c "${JAVA_LINTER_RULES}") LINTER_COMMANDS_ARRAY_JAVASCRIPT_ES=(eslint -c "${JAVASCRIPT_ES_LINTER_RULES}") LINTER_COMMANDS_ARRAY_JAVASCRIPT_PRETTIER=("${PRETTIER_COMMAND[@]}") LINTER_COMMANDS_ARRAY_JAVASCRIPT_STANDARD=(standard "${JAVASCRIPT_STANDARD_LINTER_RULES}") diff --git a/lib/globals/linterRules.sh b/lib/globals/linterRules.sh index 2aee44ae..d08f728b 100755 --- a/lib/globals/linterRules.sh +++ b/lib/globals/linterRules.sh @@ -37,6 +37,8 @@ HTML_FILE_NAME=".htmlhintrc" # shellcheck disable=SC2034 # Variable is referenced indirectly JAVA_FILE_NAME="${JAVA_FILE_NAME:-sun_checks.xml}" # shellcheck disable=SC2034 # Variable is referenced indirectly +JAVA_COMMAND_ARGS="${JAVA_COMMAND_ARGS:-null}" +# shellcheck disable=SC2034 # Variable is referenced indirectly JAVASCRIPT_ES_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" # shellcheck disable=SC2034 # Variable is referenced indirectly JAVASCRIPT_STANDARD_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}" diff --git a/test/lib/linterCommandsTest.sh b/test/lib/linterCommandsTest.sh index d0c01f06..95d56741 100755 --- a/test/lib/linterCommandsTest.sh +++ b/test/lib/linterCommandsTest.sh @@ -340,6 +340,8 @@ CommandOptionsTest() { # shellcheck disable=SC2034 GITHUB_ACTIONS_COMMAND_ARGS="-color -debug -verbose -version" # shellcheck disable=SC2034 + JAVA_COMMAND_ARGS="-Dproperty1=value1 -version" + # shellcheck disable=SC2034 KUBERNETES_KUBECONFORM_OPTIONS="-debug -verbose -v" # shellcheck disable=SC2034 PERL_PERLCRITIC_OPTIONS="--gentle --count test/linters/perl/perl_good_1.pl" @@ -352,6 +354,7 @@ CommandOptionsTest() { # Try running the commands "${LINTER_COMMANDS_ARRAY_GITHUB_ACTIONS[@]}" + "${LINTER_COMMANDS_ARRAY_JAVA[@]}" "${LINTER_COMMANDS_ARRAY_KUBERNETES_KUBECONFORM[@]}" "${LINTER_COMMANDS_ARRAY_PERL[@]}" # Rust Clippy is only available in the standard image, so we can't run it when