chore: extract language array definition (#5945)

Move LANGUAGE_ARRAY definition and initialization to a dedicated file
(globals/languages.sh) so we can source it in different places without
having to source the whole linter.sh
This commit is contained in:
Marco Ferrari 2024-07-31 17:00:41 +02:00 committed by GitHub
parent c5ba6872c6
commit d9592327c6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 61 additions and 31 deletions

View file

@ -281,7 +281,15 @@ lint-subset-files-enable-expensive-io-checks: ## Lint a small subset of files in
$(SUPER_LINTER_TEST_CONTAINER_URL)
.PHONY: test-lib
test-lib: test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output ## Test super-linter
test-lib: test-globals-languages test-build-file-list test-detect-files test-github-event test-setup-ssh test-validation test-output ## Test super-linter libs and globals
.PHONY: test-globals-languages
test-globals-languages: ## Test globals/languages.sh
docker run \
-v "$(CURDIR):/tmp/lint" \
-w /tmp/lint \
--entrypoint /tmp/lint/test/lib/globalsLanguagesTest.sh \
$(SUPER_LINTER_TEST_CONTAINER_URL)
.PHONY: test-build-file-list
test-build-file-list: ## Test buildFileList

View file

@ -90,6 +90,7 @@ new tool, it should include:
- Update the orchestration scripts to run the new tool:
- `lib/linter.sh`
- `globals/languages.sh`
- `lib/functions/linterCommands.sh`
- Provide the logic to populate the list of files or directories to examine: `lib/buildFileList.sh`
- If necessary, provide elaborate logic to detect if the tool should examine a file or a directory: `lib/detectFiles.sh`

17
lib/globals/languages.sh Executable file
View file

@ -0,0 +1,17 @@
#!/usr/bin/env bash
# shellcheck disable=SC2034
LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT'
'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CPP' 'CSHARP' 'CSS' 'DART'
'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GITHUB_ACTIONS'
'GITLEAKS' 'GHERKIN' 'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT' 'GROOVY' 'HTML' 'JAVA'
'JAVASCRIPT_ES' 'JAVASCRIPT_PRETTIER' 'JAVASCRIPT_STANDARD' 'JSCPD' 'JSON' 'JSONC' 'JSX'
'KUBERNETES_KUBECONFORM' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN'
'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN'
'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT'
'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'PYTHON_RUFF'
'R' 'RAKU' 'RENOVATE' 'RUBY' 'RUST_2015'
'RUST_2018' 'RUST_2021' 'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT'
'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'SQLFLUFF' 'TEKTON'
'TERRAFORM_FMT' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX'
'TYPESCRIPT_ES' 'TYPESCRIPT_PRETTIER' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')

View file

@ -265,23 +265,8 @@ TYPESCRIPT_ES_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
# shellcheck disable=SC2034 # Variable is referenced indirectly
YAML_FILE_NAME="${YAML_CONFIG_FILE:-.yaml-lint.yml}"
##################
# Language array #
##################
LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT'
'CLOUDFORMATION' 'CLOJURE' 'COFFEESCRIPT' 'CPP' 'CSHARP' 'CSS' 'DART'
'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GITHUB_ACTIONS'
'GITLEAKS' 'GHERKIN' 'GO' 'GO_MODULES' 'GO_RELEASER' 'GOOGLE_JAVA_FORMAT' 'GROOVY' 'HTML' 'JAVA'
'JAVASCRIPT_ES' 'JAVASCRIPT_PRETTIER' 'JAVASCRIPT_STANDARD' 'JSCPD' 'JSON' 'JSONC' 'JSX'
'KUBERNETES_KUBECONFORM' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN'
'NATURAL_LANGUAGE' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN'
'PHP_PSALM' 'POWERSHELL' 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT'
'PYTHON_FLAKE8' 'PYTHON_ISORT' 'PYTHON_MYPY' 'PYTHON_RUFF'
'R' 'RAKU' 'RENOVATE' 'RUBY' 'RUST_2015'
'RUST_2018' 'RUST_2021' 'RUST_CLIPPY' 'SCALAFMT' 'SHELL_SHFMT'
'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'SQLFLUFF' 'TEKTON'
'TERRAFORM_FMT' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX'
'TYPESCRIPT_ES' 'TYPESCRIPT_PRETTIER' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
# shellcheck source=/dev/null
source /action/lib/globals/languages.sh
##########################
# Array of changed files #

View file

@ -471,6 +471,7 @@ control "super-linter-validate-files" do
"/action/lib/functions/updateSSL.sh",
"/action/lib/functions/validation.sh",
"/action/lib/functions/worker.sh",
"/action/lib/globals/languages.sh",
"/action/lib/.automation/actionlint.yml",
"/action/lib/.automation/.ansible-lint.yml",
"/action/lib/.automation/.arm-ttk.psd1",

View file

@ -4,8 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"

View file

@ -10,9 +10,6 @@ LOG_LEVEL="DEBUG"
# shellcheck source=/dev/null
source "lib/functions/log.sh"
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# shellcheck source=/dev/null
source "lib/functions/detectFiles.sh"

View file

@ -4,8 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"

View file

@ -0,0 +1,31 @@
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"
# shellcheck source=/dev/null
source "lib/functions/log.sh"
# shellcheck source=/dev/null
source "lib/globals/languages.sh"
function LanguageArrayNotEmptyTest() {
local FUNCTION_NAME
FUNCTION_NAME="${FUNCNAME[0]}"
info "${FUNCTION_NAME} start"
if [ ${#LANGUAGE_ARRAY[@]} -gt 0 ]; then
debug "Language array is not empty as expected"
else
fatal "Language array is empty"
fi
notice "${FUNCTION_NAME} PASS"
}
LanguageArrayNotEmptyTest

View file

@ -3,8 +3,6 @@ set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"

View file

@ -4,8 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"

View file

@ -4,8 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail
# shellcheck disable=SC2034
CREATE_LOG_FILE=false
# Default log level
# shellcheck disable=SC2034
LOG_LEVEL="DEBUG"