From 888bc7524ea80c6799a9bd6b2b253b8a0224e964 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Fri, 30 Oct 2020 12:15:16 +0100 Subject: [PATCH 1/2] Don't override the secondary rules file path, if available --- README.md | 2 +- TEMPLATES/{.hadolint.yml => .hadolint.yaml} | 0 docs/disabling-linters.md | 6 ++-- lib/linter.sh | 31 ++++++++++----------- 4 files changed, 19 insertions(+), 20 deletions(-) rename TEMPLATES/{.hadolint.yml => .hadolint.yaml} (100%) diff --git a/README.md b/README.md index 49806ec5..cfc71370 100644 --- a/README.md +++ b/README.md @@ -210,7 +210,7 @@ But if you wish to select or exclude specific linters, we give you full control | **DEFAULT_BRANCH** | `master` | The name of the repository default branch. | | **DEFAULT_WORKSPACE** | `/tmp/lint` | The location containing files to lint if you are running locally. | | **DISABLE_ERRORS** | `false` | Flag to have the linter complete with exit code 0 even if errors were detected. | -| **DOCKERFILE_HADOLINT_FILE_NAME** | `.hadolint.yml` | Filename for [hadolint configuration](https://github.com/hadolint/hadolint) (ex: `.hadolintlintrc.yaml`) | +| **DOCKERFILE_HADOLINT_FILE_NAME** | `.hadolint.yaml` | Filename for [hadolint configuration](https://github.com/hadolint/hadolint) (ex: `.hadolint.yaml`) | | **EDITORCONFIG_FILE_NAME** | `.ecrc` | Filename for [editorconfig-checker configuration](https://github.com/editorconfig-checker/editorconfig-checker) | | **ERROR_ON_MISSING_EXEC_BIT** | `false` | If set to `false`, the `bash-exec` linter will report a warning if a shell script is not executable. If set to `true`, the `bash-exec` linter will report an arror instead. | | **FILTER_REGEX_EXCLUDE** | `none` | Regular expression defining which files will be excluded from linting (ex: `.*src/test.*`) | diff --git a/TEMPLATES/.hadolint.yml b/TEMPLATES/.hadolint.yaml similarity index 100% rename from TEMPLATES/.hadolint.yml rename to TEMPLATES/.hadolint.yaml diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index ca3947ce..1c254c92 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -311,9 +311,9 @@ analyzer: ### Hadolint standard Config file -- `.github/linters/.hadolint.yml` +- `.github/linters/.hadolint.yaml` - 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 @@ -1009,7 +1009,7 @@ var = "terrible code down here..." - `.github/linters/.lintr` - You can pass multiple rules and overwrite default rules - You can use either one `.lintr` file in the root of your repository and/or additonal `.lintr` files in subdirectories. When linting a file lintr will look for config files from the file location upwards and will use the closest one. -- Absolute paths for exclusions will not work due to the code being linted within the docker environment. Use paths relative to the `.lintr` file in which youare adding them. +- Absolute paths for exclusions will not work due to the code being linted within the docker environment. Use paths relative to the `.lintr` file in which youare adding them. - **Note:** The defaults adhere to the [tidyverse styleguide](https://style.tidyverse.org/) ### lintr disable single line diff --git a/lib/linter.sh b/lib/linter.sh index f63d4756..c18d1a2f 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -70,7 +70,7 @@ CSS_FILE_NAME="${CSS_FILE_NAME:-.stylelintrc.json}" DART_FILE_NAME="analysis_options.yml" # shellcheck disable=SC2034 # Variable is referenced indirectly 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}" # shellcheck disable=SC2034 # Variable is referenced indirectly GO_FILE_NAME=".golangci.yml" @@ -407,24 +407,23 @@ GetLinterRules() { # Update the path to the file location # ######################################## eval "${LANGUAGE_LINTER_RULES}=${LANGUAGE_FILE_PATH}" - else - debug " -> Codebase does NOT have file:[${LANGUAGE_FILE_PATH}]" - # Check if we have secondary name to check - if [ -n "$SECONDARY_FILE_NAME" ]; then - 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}" - if [ -f "${SECONDARY_LANGUAGE_FILE_PATH}" ]; then - info "----------------------------------------------" - info "User provided file:[${SECONDARY_LANGUAGE_FILE_PATH}] exists, setting rules file..." + # Check if we have secondary file name to look for + elif [ -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}" + debug "${LANGUAGE_NAME} language rule file has a secondary rules file name to check (${SECONDARY_FILE_NAME}). Path: ${SECONDARY_LANGUAGE_FILE_PATH}" - ######################################## - # Update the path to the file location # - ######################################## - eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}" - fi + if [ -f "${SECONDARY_LANGUAGE_FILE_PATH}" ]; then + info "----------------------------------------------" + info "User provided file:[${SECONDARY_LANGUAGE_FILE_PATH}] exists, setting rules file..." + + ######################################## + # Update the path to the file location # + ######################################## + eval "${LANGUAGE_LINTER_RULES}=${SECONDARY_LANGUAGE_FILE_PATH}" fi - + else ######################################################## # No user default provided, using the template default # ######################################################## From e2f45db57d29d84afa2dfb86a235e298be572d93 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Fri, 30 Oct 2020 12:35:32 +0100 Subject: [PATCH 2/2] Initialize the LANGUAGE_LINTER_RULES value to avoid using leftovers from the previous iteration --- lib/linter.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index c18d1a2f..a1800742 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -371,6 +371,9 @@ GetLinterRules() { return fi + debug "Initializing LANGUAGE_LINTER_RULES value to an empty string..." + eval "${LANGUAGE_LINTER_RULES}=" + ########################## # Get the file extension # ########################## @@ -378,10 +381,12 @@ GetLinterRules() { 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" - ############################### - # 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_LANGUAGE_FILE_PATH= ################################# # Check for secondary file name # @@ -428,7 +433,7 @@ GetLinterRules() { # No user default provided, using the template default # ######################################################## 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 debug " -> Language rules file variable (${LANGUAGE_LINTER_RULES}) value is: ${!LANGUAGE_LINTER_RULES}"