mirror of
https://github.com/super-linter/super-linter.git
synced 2024-11-21 21:50:59 -05:00
chore: move rules vars to a dedicated file (#5946)
This commit is contained in:
parent
c46346c774
commit
14a6ee6da6
8 changed files with 233 additions and 113 deletions
10
Makefile
10
Makefile
|
@ -281,7 +281,7 @@ 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-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
|
||||
test-lib: test-globals-languages test-linter-rules 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
|
||||
|
@ -291,6 +291,14 @@ test-globals-languages: ## Test globals/languages.sh
|
|||
--entrypoint /tmp/lint/test/lib/globalsLanguagesTest.sh \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-linter-rules
|
||||
test-linter-rules: ## Test linterRules.sh
|
||||
docker run \
|
||||
-v "$(CURDIR):/tmp/lint" \
|
||||
-w /tmp/lint \
|
||||
--entrypoint /tmp/lint/test/lib/linterRulesTest.sh \
|
||||
$(SUPER_LINTER_TEST_CONTAINER_URL)
|
||||
|
||||
.PHONY: test-build-file-list
|
||||
test-build-file-list: ## Test buildFileList
|
||||
docker run \
|
||||
|
|
|
@ -89,9 +89,23 @@ new tool, it should include:
|
|||
|
||||
- Update the orchestration scripts to run the new tool:
|
||||
|
||||
- `globals/languages.sh`: add a new item to `LANGUAGES_ARRAY` array. Use the
|
||||
"name" of the language, then a `_`, and finally the name of the linter. Example: `PYTHON_RUFF`
|
||||
- Linter configuration:
|
||||
- `globals/linterRules.sh`:
|
||||
- If the new linter accepts a configuration files from the command line, add a new variable
|
||||
with a default filename using the item that you added to the `LANGUAGES_ARRAY` as a prefix,
|
||||
followed by the `CONFIG_FILE` suffix. Example:
|
||||
`PYTHON_RUFF_FILE_NAME="${PYTHON_RUFF_CONFIG_FILE:-.ruff.toml}"`.
|
||||
- If there are arguments that you can only pass using the command line, and you think users
|
||||
might want to customize them, define a new variable using the item that
|
||||
you added to the `LANGUAGES_ARRAY` as a prefix, followed by the
|
||||
`COMMAND_ARGS` suffix. Example:
|
||||
`GITHUB_ACTIONS_COMMAND_ARGS="${GITHUB_ACTIONS_COMMAND_ARGS:-""}"`
|
||||
- Create a new minimal configuration file in the `TEMPLATES` directory with the same name as the
|
||||
default configuration filename. Example: `TEMPLATES/.ruff.toml`.
|
||||
- `lib/linter.sh`
|
||||
- `globals/languages.sh`
|
||||
- `lib/functions/linterCommands.sh`
|
||||
- `lib/functions/linterCommands.sh`: define a new array to invoke the new linter.
|
||||
- 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`
|
||||
- If the tool needs to take into account special cases:
|
||||
|
|
|
@ -15,3 +15,5 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CHECKOV' 'CLANG_FORMAT'
|
|||
'SNAKEMAKE_LINT' 'SNAKEMAKE_SNAKEFMT' 'STATES' 'SQL' 'SQLFLUFF' 'TEKTON'
|
||||
'TERRAFORM_FMT' 'TERRAFORM_TFLINT' 'TERRAFORM_TERRASCAN' 'TERRAGRUNT' 'TSX'
|
||||
'TYPESCRIPT_ES' 'TYPESCRIPT_PRETTIER' 'TYPESCRIPT_STANDARD' 'XML' 'YAML')
|
||||
|
||||
LANGUAGE_ARRAY_FOR_LINTER_RULES=("${LANGUAGE_ARRAY[@]}" "TYPESCRIPT_STANDARD_TSCONFIG")
|
||||
|
|
107
lib/globals/linterRules.sh
Executable file
107
lib/globals/linterRules.sh
Executable file
|
@ -0,0 +1,107 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory
|
||||
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
ANSIBLE_FILE_NAME="${ANSIBLE_CONFIG_FILE:-.ansible-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
ARM_FILE_NAME=".arm-ttk.psd1"
|
||||
BASH_FILE_NAME="${BASH_FILE_NAME:-".shellcheckrc"}"
|
||||
BASH_SEVERITY="${BASH_SEVERITY:-""}"
|
||||
CHECKOV_FILE_NAME="${CHECKOV_FILE_NAME:-".checkov.yaml"}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLANG_FORMAT_FILE_NAME="${CLANG_FORMAT_FILE_NAME:-".clang-format"}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLOJURE_FILE_NAME=".clj-kondo/config.edn"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLOUDFORMATION_FILE_NAME=".cfnlintrc.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
COFFEESCRIPT_FILE_NAME=".coffee-lint.json"
|
||||
CSS_FILE_NAME="${CSS_FILE_NAME:-.stylelintrc.json}"
|
||||
DOCKERFILE_HADOLINT_FILE_NAME="${DOCKERFILE_HADOLINT_FILE_NAME:-.hadolint.yaml}"
|
||||
EDITORCONFIG_FILE_NAME="${EDITORCONFIG_FILE_NAME:-.ecrc}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITHUB_ACTIONS_FILE_NAME="${GITHUB_ACTIONS_CONFIG_FILE:-actionlint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITHUB_ACTIONS_COMMAND_ARGS="${GITHUB_ACTIONS_COMMAND_ARGS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITLEAKS_FILE_NAME="${GITLEAKS_CONFIG_FILE:-.gitleaks.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GHERKIN_FILE_NAME=".gherkin-lintrc"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GO_FILE_NAME=".golangci.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GROOVY_FILE_NAME=".groovylintrc.json"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
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
|
||||
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}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
JSCPD_FILE_NAME="${JSCPD_CONFIG_FILE:-.jscpd.json}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
JSX_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
KUBERNETES_KUBECONFORM_OPTIONS="${KUBERNETES_KUBECONFORM_OPTIONS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
LATEX_FILE_NAME=".chktexrc"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
LUA_FILE_NAME=".luacheckrc"
|
||||
MARKDOWN_CUSTOM_RULE_GLOBS="${MARKDOWN_CUSTOM_RULE_GLOBS:-""}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
MARKDOWN_FILE_NAME="${MARKDOWN_CONFIG_FILE:-.markdown-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
OPENAPI_FILE_NAME=".openapirc.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PERL_PERLCRITIC_OPTIONS="${PERL_PERLCRITIC_OPTIONS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_BUILTIN_FILE_NAME="${PHP_CONFIG_FILE:-php.ini}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PHPCS_FILE_NAME="${PHP_PHPCS_FILE_NAME:-phpcs.xml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PHPSTAN_FILE_NAME="${PHP_PHPSTAN_CONFIG_FILE:-phpstan.neon}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PSALM_FILE_NAME="psalm.xml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
POWERSHELL_FILE_NAME="${POWERSHELL_CONFIG_FILE:-.powershell-psscriptanalyzer.psd1}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PROTOBUF_FILE_NAME="${PROTOBUF_CONFIG_FILE:-.protolintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_BLACK_FILE_NAME="${PYTHON_BLACK_CONFIG_FILE:-.python-black}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_ISORT_FILE_NAME="${PYTHON_ISORT_CONFIG_FILE:-.isort.cfg}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_MYPY_FILE_NAME="${PYTHON_MYPY_CONFIG_FILE:-.mypy.ini}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_RUFF_FILE_NAME="${PYTHON_RUFF_CONFIG_FILE:-.ruff.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
R_FILE_NAME=".lintr"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SQL_FILE_NAME="${SQL_CONFIG_FILE:-.sql-config.json}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SQLFLUFF_FILE_NAME="${SQLFLUFF_CONFIG_FILE:-/.sqlfluff}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TERRAFORM_TFLINT_FILE_NAME="${TERRAFORM_TFLINT_CONFIG_FILE:-.tflint.hcl}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TERRAFORM_TERRASCAN_FILE_NAME="${TERRAFORM_TERRASCAN_CONFIG_FILE:-terrascan.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
NATURAL_LANGUAGE_FILE_NAME="${NATURAL_LANGUAGE_CONFIG_FILE:-.textlintrc}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TSX_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
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}"
|
113
lib/linter.sh
113
lib/linter.sh
|
@ -152,7 +152,6 @@ FILTER_REGEX_INCLUDE="${FILTER_REGEX_INCLUDE:-""}"
|
|||
export FILTER_REGEX_INCLUDE
|
||||
FILTER_REGEX_EXCLUDE="${FILTER_REGEX_EXCLUDE:-""}"
|
||||
export FILTER_REGEX_EXCLUDE
|
||||
LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter rules directory
|
||||
# shellcheck disable=SC2034 # Variable is referenced in other scripts
|
||||
RAW_FILE_ARRAY=() # Array of all files that were changed
|
||||
# shellcheck disable=SC2034 # Variable is referenced in other scripts
|
||||
|
@ -169,113 +168,11 @@ TFLINT_LOG="${TF_LOG_LEVEL}"
|
|||
export TFLINT_LOG
|
||||
debug "TFLINT_LOG: ${TFLINT_LOG}"
|
||||
|
||||
###############
|
||||
# Rules files #
|
||||
###############
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
ANSIBLE_FILE_NAME="${ANSIBLE_CONFIG_FILE:-.ansible-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
ARM_FILE_NAME=".arm-ttk.psd1"
|
||||
BASH_FILE_NAME="${BASH_FILE_NAME:-".shellcheckrc"}"
|
||||
BASH_SEVERITY="${BASH_SEVERITY:-""}"
|
||||
CHECKOV_FILE_NAME="${CHECKOV_FILE_NAME:-".checkov.yaml"}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLANG_FORMAT_FILE_NAME="${CLANG_FORMAT_FILE_NAME:-".clang-format"}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLOJURE_FILE_NAME=".clj-kondo/config.edn"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
CLOUDFORMATION_FILE_NAME=".cfnlintrc.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
COFFEESCRIPT_FILE_NAME=".coffee-lint.json"
|
||||
CSS_FILE_NAME="${CSS_FILE_NAME:-.stylelintrc.json}"
|
||||
DOCKERFILE_HADOLINT_FILE_NAME="${DOCKERFILE_HADOLINT_FILE_NAME:-.hadolint.yaml}"
|
||||
EDITORCONFIG_FILE_NAME="${EDITORCONFIG_FILE_NAME:-.ecrc}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITHUB_ACTIONS_FILE_NAME="${GITHUB_ACTIONS_CONFIG_FILE:-actionlint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITHUB_ACTIONS_COMMAND_ARGS="${GITHUB_ACTIONS_COMMAND_ARGS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GITLEAKS_FILE_NAME="${GITLEAKS_CONFIG_FILE:-.gitleaks.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GHERKIN_FILE_NAME=".gherkin-lintrc"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GO_FILE_NAME=".golangci.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
GROOVY_FILE_NAME=".groovylintrc.json"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
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
|
||||
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}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
JSCPD_FILE_NAME="${JSCPD_CONFIG_FILE:-.jscpd.json}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
JSX_FILE_NAME="${JAVASCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
KUBERNETES_KUBECONFORM_OPTIONS="${KUBERNETES_KUBECONFORM_OPTIONS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
LATEX_FILE_NAME=".chktexrc"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
LUA_FILE_NAME=".luacheckrc"
|
||||
MARKDOWN_CUSTOM_RULE_GLOBS="${MARKDOWN_CUSTOM_RULE_GLOBS:-""}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
MARKDOWN_FILE_NAME="${MARKDOWN_CONFIG_FILE:-.markdown-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
OPENAPI_FILE_NAME=".openapirc.yml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PERL_PERLCRITIC_OPTIONS="${PERL_PERLCRITIC_OPTIONS:-null}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_BUILTIN_FILE_NAME="${PHP_CONFIG_FILE:-php.ini}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PHPCS_FILE_NAME="${PHP_PHPCS_FILE_NAME:-phpcs.xml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PHPSTAN_FILE_NAME="${PHP_PHPSTAN_CONFIG_FILE:-phpstan.neon}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PHP_PSALM_FILE_NAME="psalm.xml"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
POWERSHELL_FILE_NAME="${POWERSHELL_CONFIG_FILE:-.powershell-psscriptanalyzer.psd1}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PROTOBUF_FILE_NAME="${PROTOBUF_CONFIG_FILE:-.protolintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_BLACK_FILE_NAME="${PYTHON_BLACK_CONFIG_FILE:-.python-black}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_FLAKE8_FILE_NAME="${PYTHON_FLAKE8_CONFIG_FILE:-.flake8}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_ISORT_FILE_NAME="${PYTHON_ISORT_CONFIG_FILE:-.isort.cfg}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_MYPY_FILE_NAME="${PYTHON_MYPY_CONFIG_FILE:-.mypy.ini}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_PYLINT_FILE_NAME="${PYTHON_PYLINT_CONFIG_FILE:-.python-lint}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
PYTHON_RUFF_FILE_NAME="${PYTHON_RUFF_CONFIG_FILE:-.ruff.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
R_FILE_NAME=".lintr"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
RUBY_FILE_NAME="${RUBY_CONFIG_FILE:-.ruby-lint.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SCALAFMT_FILE_NAME="${SCALAFMT_CONFIG_FILE:-.scalafmt.conf}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SNAKEMAKE_SNAKEFMT_FILE_NAME="${SNAKEMAKE_SNAKEFMT_CONFIG_FILE:-.snakefmt.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SQL_FILE_NAME="${SQL_CONFIG_FILE:-.sql-config.json}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
SQLFLUFF_FILE_NAME="${SQLFLUFF_CONFIG_FILE:-/.sqlfluff}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TERRAFORM_TFLINT_FILE_NAME="${TERRAFORM_TFLINT_CONFIG_FILE:-.tflint.hcl}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TERRAFORM_TERRASCAN_FILE_NAME="${TERRAFORM_TERRASCAN_CONFIG_FILE:-terrascan.toml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
NATURAL_LANGUAGE_FILE_NAME="${NATURAL_LANGUAGE_CONFIG_FILE:-.textlintrc}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
TSX_FILE_NAME="${TYPESCRIPT_ES_CONFIG_FILE:-.eslintrc.yml}"
|
||||
# shellcheck disable=SC2034 # Variable is referenced indirectly
|
||||
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}"
|
||||
# Load linter configuration and rules files
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/globals/linterRules.sh
|
||||
|
||||
# Load languages array
|
||||
# shellcheck source=/dev/null
|
||||
source /action/lib/globals/languages.sh
|
||||
|
||||
|
@ -883,8 +780,6 @@ LinterRulesLocation
|
|||
########################
|
||||
# Get the linter rules #
|
||||
########################
|
||||
LANGUAGE_ARRAY_FOR_LINTER_RULES=("${LANGUAGE_ARRAY[@]}" "TYPESCRIPT_STANDARD_TSCONFIG")
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY_FOR_LINTER_RULES[@]}"; do
|
||||
debug "Loading rules for ${LANGUAGE}..."
|
||||
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
|
||||
|
|
|
@ -472,6 +472,7 @@ control "super-linter-validate-files" do
|
|||
"/action/lib/functions/validation.sh",
|
||||
"/action/lib/functions/worker.sh",
|
||||
"/action/lib/globals/languages.sh",
|
||||
"/action/lib/globals/linterRules.sh",
|
||||
"/action/lib/.automation/actionlint.yml",
|
||||
"/action/lib/.automation/.ansible-lint.yml",
|
||||
"/action/lib/.automation/.arm-ttk.psd1",
|
||||
|
|
|
@ -52,7 +52,7 @@ function GenerateFileDiffOneFileTest() {
|
|||
GITHUB_WORKSPACE="$(mktemp -d)"
|
||||
# shellcheck disable=SC2064 # Once the path is set, we don't expect it to change
|
||||
trap "rm -fr '${GITHUB_WORKSPACE}'" EXIT
|
||||
echo "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
|
||||
debug "GITHUB_WORKSPACE: ${GITHUB_WORKSPACE}"
|
||||
|
||||
local FILES_TO_COMMIT="${FILES_TO_COMMIT:-1}"
|
||||
local COMMIT_FILE_INITIAL_COMMIT="${COMMIT_FILE_INITIAL_COMMIT:-"false"}"
|
||||
|
|
93
test/lib/linterRulesTest.sh
Executable file
93
test/lib/linterRulesTest.sh
Executable file
|
@ -0,0 +1,93 @@
|
|||
#!/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/linterRules.sh"
|
||||
|
||||
TEST_LANGUAGE_NAME="TEST_LANGUAGE"
|
||||
TEST_LANGUAGE_NAME_WITHOUT_RULES="TEST_LANGUAGE_WITHOUT_RULES"
|
||||
LANGUAGE_ARRAY=("${TEST_LANGUAGE_NAME}" "${TEST_LANGUAGE_NAME_WITHOUT_RULES}")
|
||||
|
||||
# shellcheck source=/dev/null
|
||||
source "lib/functions/linterRules.sh"
|
||||
|
||||
DEFAULT_RULES_LOCATION="TEMPLATES"
|
||||
|
||||
# Use an existing configuration file. Can be anything inside
|
||||
# DEFAULT_RULES_LOCATION
|
||||
# shellcheck disable=SC2034
|
||||
TEST_LANGUAGE_FILE_NAME=".eslintrc.yml"
|
||||
|
||||
# shellcheck disable=SC2034
|
||||
GITHUB_WORKSPACE="$(pwd)"
|
||||
|
||||
function GetLinterRulesTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
debug "Loading rules for ${LANGUAGE}..."
|
||||
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
|
||||
done
|
||||
|
||||
local EXPECTED_TEST_LANGUAGE_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${TEST_LANGUAGE_FILE_NAME}"
|
||||
if [[ "${TEST_LANGUAGE_LINTER_RULES}" == "${EXPECTED_TEST_LANGUAGE_LINTER_RULES}" ]]; then
|
||||
debug "TEST_LANGUAGE_LINTER_RULES (${TEST_LANGUAGE_LINTER_RULES}) matches the expected value (${EXPECTED_TEST_LANGUAGE_LINTER_RULES})"
|
||||
else
|
||||
fatal "TEST_LANGUAGE_LINTER_RULES (${TEST_LANGUAGE_LINTER_RULES}) doesn't match the expected value (${EXPECTED_TEST_LANGUAGE_LINTER_RULES})"
|
||||
fi
|
||||
if [[ -z "${TEST_LANGUAGE_WITHOUT_RULES_LINTER_RULES:-}" ]]; then
|
||||
debug "TEST_LANGUAGE_WITHOUT_RULES_LINTER_RULES is not set as expected"
|
||||
else
|
||||
fatal "TEST_LANGUAGE_WITHOUT_RULES_LINTER_RULES shouldn't be set"
|
||||
fi
|
||||
unset TEST_LANGUAGE_LINTER_RULES
|
||||
unset TEST_LANGUAGE_WITHOUT_RULES_LINTER_RULES
|
||||
unset EXPECTED_TEST_LANGUAGE_LINTER_RULES
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
function LinterRulesVariablesExportTest() {
|
||||
local FUNCTION_NAME
|
||||
FUNCTION_NAME="${FUNCNAME[0]}"
|
||||
info "${FUNCTION_NAME} start"
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
debug "Loading rules for ${LANGUAGE}..."
|
||||
eval "GetLinterRules ${LANGUAGE} ${DEFAULT_RULES_LOCATION}"
|
||||
done
|
||||
|
||||
for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do
|
||||
if [[ "${LANGUAGE}" == "${TEST_LANGUAGE_NAME_WITHOUT_RULES}" ]]; then
|
||||
debug "${LANGUAGE} doesn't have linter rules. Skipping export test."
|
||||
continue
|
||||
fi
|
||||
|
||||
local -n LANGUAGE_LINTER_RULES
|
||||
LANGUAGE_LINTER_RULES="${LANGUAGE}_LINTER_RULES"
|
||||
debug "LANGUAGE_LINTER_RULES (${LANGUAGE}) variable attributes: ${LANGUAGE_LINTER_RULES@a}"
|
||||
if [[ "${LANGUAGE_LINTER_RULES@a}" == *x* ]]; then
|
||||
info "LANGUAGE_LINTER_RULES for ${LANGUAGE} is exported as expected"
|
||||
else
|
||||
fatal "LANGUAGE_LINTER_RULES for ${LANGUAGE} should have been exported"
|
||||
fi
|
||||
unset -n LANGUAGE_LINTER_RULES
|
||||
done
|
||||
|
||||
notice "${FUNCTION_NAME} PASS"
|
||||
}
|
||||
|
||||
GetLinterRulesTest
|
||||
LinterRulesVariablesExportTest
|
Loading…
Reference in a new issue