From cb2cf0eb49783f6ac3faad8073d45587725159c9 Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 11 Aug 2020 21:04:33 -0500 Subject: [PATCH 1/3] Fix spell --- lib/worker.sh | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/lib/worker.sh b/lib/worker.sh index a64a67cb..09868ef3 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -78,7 +78,7 @@ function LintCodebase() { LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list else ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # + # Set the file separator to newline to allow for grabbing objects with spaces # ############################################################################### IFS=$'\n' @@ -141,9 +141,9 @@ function LintCodebase() { FILE_NAME=$(basename "${FILE}" 2>&1) DIR_NAME=$(dirname "${FILE}" 2>&1) - ##################################################### - # Make sure we dont lint node modules or test cases # - ##################################################### + ###################################################### + # Make sure we don't lint node modules or test cases # + ###################################################### if [[ ${FILE} == *"node_modules"* ]]; then # This is a node modules file continue @@ -151,7 +151,7 @@ function LintCodebase() { # This is the test cases, we should always skip continue elif [[ ${FILE} == *".git"* ]]; then - # This is likely the .git folder and shouldnt be parsed + # This is likely the .git folder and shouldn't be parsed continue fi @@ -270,7 +270,7 @@ function TestCodebase() { LINTER_NAME="${2}" # Pull the variable and remove from array path (Example: jsonlint) LINTER_COMMAND="${3}" # Pull the variable and remove from array path (Example: jsonlint -c ConfigFile /path/to/file) FILE_EXTENSIONS="${4}" # Pull the variable and remove from array path (Example: *.json) - INDVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests + INDIVIDUAL_TEST_FOLDER="${5}" # Folder for specific tests TESTS_RAN=0 # Incremented when tests are ran, this will help find failed finds ################ @@ -312,7 +312,7 @@ function TestCodebase() { ################################# # Get list of all files to lint # ################################# - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" -path "*/node_modules" -prune -o -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDIVIDUAL_TEST_FOLDER}" -path "*/node_modules" -prune -o -type f -regex "${FILE_EXTENSIONS}" ! -path "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/ansible/ghe-initialize/*" | sort 2>&1) ######################################## # Prepare context if TAP output format # @@ -381,11 +381,11 @@ function TestCodebase() { # Check for ansible # ##################### if [[ ${FILE_TYPE} == "ANSIBLE" ]]; then - ######################################## - # Make sure we dont lint certain files # - ######################################## + ######################################### + # Make sure we don't lint certain files # + ######################################### if [[ ${FILE} == *"vault.yml"* ]] || [[ ${FILE} == *"galaxy.yml"* ]]; then - # This is a file we dont look at + # This is a file we don't look at continue fi @@ -393,7 +393,7 @@ function TestCodebase() { # Lint the file with the rules # ################################ LINT_CMD=$( - cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}" || exit + cd "${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDIVIDUAL_TEST_FOLDER}" || exit ${LINTER_COMMAND} "${FILE}" 2>&1 ) elif [[ ${FILE_TYPE} == "POWERSHELL" ]] || [[ ${FILE_TYPE} == "ARM" ]]; then @@ -509,7 +509,7 @@ function TestCodebase() { ######################################################################## # If expected TAP report exists then compare with the generated report # ######################################################################## - EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" + EXPECTED_FILE="${GITHUB_WORKSPACE}/${TEST_CASE_FOLDER}/${INDIVIDUAL_TEST_FOLDER}/reports/expected-${FILE_TYPE}.tap" if [ -e "${EXPECTED_FILE}" ]; then TMPFILE=$(mktemp -q "/tmp/diff-${FILE_TYPE}.XXXXXX") ## Ignore white spaces, case sensitive From d05f179506ba3d376680f8f2711712214bc75e99 Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 11 Aug 2020 21:05:01 -0500 Subject: [PATCH 2/3] Add logic to include/exclude linters --- lib/validation.sh | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/validation.sh b/lib/validation.sh index 6e4105b0..c63ea87e 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -57,6 +57,8 @@ function GetValidationInfo() { # Determine if any linters were explicitly set # ################################################ ANY_SET="false" + ANY_TRUE="false" + ANY_FALSE="false" # Loop through all languages for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do # build the variable @@ -65,12 +67,21 @@ function GetValidationInfo() { if [ -n "${!VALIDATE_LANGUAGE}" ]; then # It was set, need to set flag ANY_SET="true" + if [ "${!VALIDATE_LANGUAGE}" == "true" ]; then + ANY_TRUE="true" + elif [ "${!VALIDATE_LANGUAGE}" == "false" ]; then + ANY_FALSE="true" + fi fi done - ################################################### - # Validate if we should check individual lanuages # - ################################################### + if [ $ANY_TRUE == "true" ] && [ $ANY_FALSE == "true" ]; then + fatal "Behavior not supported, please either only include (VALIDATE=true) or exclude (VALIDATE=false) linters, but not both" + fi + + ######################################################### + # Validate if we should check/omit individual languages # + ######################################################### # Loop through all languages for LANGUAGE in "${LANGUAGE_ARRAY[@]}"; do # build the variable @@ -79,8 +90,10 @@ function GetValidationInfo() { if [[ ${ANY_SET} == "true" ]]; then # Check to see if the variable was set if [ -z "${!VALIDATE_LANGUAGE}" ]; then - # Flag was not set, default to false - eval "${VALIDATE_LANGUAGE}='false'" + # Flag was not set, default to: + # if ANY_TRUE then set to false + # if ANY_FALSE then set to true + eval "${VALIDATE_LANGUAGE}='$ANY_FALSE'" fi else # No linter flags were set - default all to true From 13e50cc32e88208137bc59c3a546e4e49211599d Mon Sep 17 00:00:00 2001 From: Gabo Date: Tue, 11 Aug 2020 21:16:36 -0500 Subject: [PATCH 3/3] Update documentation about VALIDATE_[LANGUAGE] vars --- README.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 167b6f37..324a5aae 100644 --- a/README.md +++ b/README.md @@ -162,12 +162,14 @@ Using the line:`uses: docker://github/super-linter:v3` will pull the image down The super-linter allows you to pass the following `ENV` variables to be able to trigger different functionality. -_Note:_ All the `VALIDATE_[LANGUAGE]` variables behave in a specific way. -If none of them are passed, then they all default to true. -However if any one of the variables are set, we default to leaving any unset variable to false. +_Note:_ All the `VALIDATE_[LANGUAGE]` variables behave in a very specific way: +- If none of them are passed, then they all default to true. +- If any one of the variables are set to true, we default to leaving any unset variable to false (only validate those languages). +- If any one of the variables are set to false, we default to leaving any unset variable to true (only exclude those languages). +- If there are `VALIDATE_[LANGUAGE]` variables set to both true and false. It will fail. + This means that if you run the linter "out of the box", all languages will be checked. -But if you wish to select specific linters, we give you full control to choose which linters are run, -and won't run anything unexpected. +But if you wish to select or exclude specific linters, we give you full control to choose which linters are run, and won't run anything unexpected. | **ENV VAR** | **Default Value** | **Notes** | | -------------------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |