Merge pull request #927 from github/fix-secondary-rules-file

Don't override the secondary rules file path if available, don't reuse dirty values from previous iterations when loading rules files
This commit is contained in:
Lukas Gravley 2020-11-02 08:58:06 -06:00 committed by GitHub
commit 5a04bd9875
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 23 deletions

View file

@ -311,9 +311,9 @@ analyzer:
### Hadolint standard Config file ### Hadolint standard Config file
- `.github/linters/.hadolint.yml` - `.github/linters/.hadolint.yaml`
- You can pass multiple rules and overwrite default rules - You can pass multiple rules and overwrite default rules
- File should be located at: `.github/linters/.hadolint.yml` - File should be located at: `.github/linters/.hadolint.yaml`
### Hadolint disable single line ### Hadolint disable single line

View file

@ -79,7 +79,7 @@ CSS_FILE_NAME="${CSS_FILE_NAME:-.stylelintrc.json}"
DART_FILE_NAME="analysis_options.yml" DART_FILE_NAME="analysis_options.yml"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
DOCKERFILE_FILE_NAME=".dockerfilelintrc" DOCKERFILE_FILE_NAME=".dockerfilelintrc"
DOCKERFILE_HADOLINT_FILE_NAME="${DOCKERFILE_HADOLINT_FILE_NAME:-.hadolint.yml}" DOCKERFILE_HADOLINT_FILE_NAME="${DOCKERFILE_HADOLINT_FILE_NAME:-.hadolint.yaml}"
EDITORCONFIG_FILE_NAME="${EDITORCONFIG_FILE_NAME:-.ecrc}" EDITORCONFIG_FILE_NAME="${EDITORCONFIG_FILE_NAME:-.ecrc}"
# shellcheck disable=SC2034 # Variable is referenced indirectly # shellcheck disable=SC2034 # Variable is referenced indirectly
GO_FILE_NAME=".golangci.yml" GO_FILE_NAME=".golangci.yml"
@ -380,6 +380,9 @@ GetLinterRules() {
return return
fi fi
debug "Initializing LANGUAGE_LINTER_RULES value to an empty string..."
eval "${LANGUAGE_LINTER_RULES}="
########################## ##########################
# Get the file extension # # Get the file extension #
########################## ##########################
@ -387,10 +390,12 @@ GetLinterRules() {
FILE_NAME=$(basename "${!LANGUAGE_FILE_NAME}" ".${FILE_EXTENSION}") FILE_NAME=$(basename "${!LANGUAGE_FILE_NAME}" ".${FILE_EXTENSION}")
debug "${LANGUAGE_NAME} language rule file (${!LANGUAGE_FILE_NAME}) has ${FILE_NAME} name and ${FILE_EXTENSION} extension" debug "${LANGUAGE_NAME} language rule file (${!LANGUAGE_FILE_NAME}) has ${FILE_NAME} name and ${FILE_EXTENSION} extension"
############################### ########################################
# Set the secondary file name # # Set the secondary file name and path #
############################### ########################################
debug "Initializing SECONDARY_FILE_NAME and SECONDARY_LANGUAGE_FILE_PATH..."
SECONDARY_FILE_NAME='' SECONDARY_FILE_NAME=''
SECONDARY_LANGUAGE_FILE_PATH=
################################# #################################
# Check for secondary file name # # Check for secondary file name #
@ -416,10 +421,10 @@ GetLinterRules() {
# Update the path to the file location # # Update the path to the file location #
######################################## ########################################
eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}" eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}"
else
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]" # Check if we have secondary file name to look for
# Check if we have secondary name to check elif [ -n "$SECONDARY_FILE_NAME" ]; then
if [ -n "$SECONDARY_FILE_NAME" ]; then debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]."
SECONDARY_LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${SECONDARY_FILE_NAME}" SECONDARY_LANGUAGE_FILE_PATH="${GITHUB_WORKSPACE}/${LINTER_RULES_PATH}/${SECONDARY_FILE_NAME}"
debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path: ${SECONDARY_LANGUAGE_FILE_PATH}" debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path: ${SECONDARY_LANGUAGE_FILE_PATH}"
@ -432,13 +437,12 @@ GetLinterRules() {
######################################## ########################################
eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}" eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}"
fi fi
fi else
######################################################## ########################################################
# No user default provided, using the template default # # No user default provided, using the template default #
######################################################## ########################################################
eval "${LANGUAGE_LINTER_RULES}=${DEFAULT_RULES_LOCATION}/${!LANGUAGE_FILE_NAME}" eval "${LANGUAGE_LINTER_RULES}=${DEFAULT_RULES_LOCATION}/${!LANGUAGE_FILE_NAME}"
debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}], nor file:[${SECONDARY_LANGUAGE_FILE_PATH}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]" debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}], nor the file:[${SECONDARY_LANGUAGE_FILE_PATH}], using Default rules at:[${!LANGUAGE_LINTER_RULES}]"
fi fi
debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is: ${!LANGUAGE_LINTER_RULES}" debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is: ${!LANGUAGE_LINTER_RULES}"