From 889179e0bf4aed42bb7a794cd65ab44d249bfeaf Mon Sep 17 00:00:00 2001 From: Eric Nemchik Date: Tue, 30 Jun 2020 09:24:28 -0500 Subject: [PATCH] Fix ShellCheck issues with new code base --- .vscode/testlinter.sh | 2 +- lib/buildFileList.sh | 6 +++--- lib/linter.sh | 11 ++++------- lib/worker.sh | 18 +++++------------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/.vscode/testlinter.sh b/.vscode/testlinter.sh index 8d778d16..69497bb5 100644 --- a/.vscode/testlinter.sh +++ b/.vscode/testlinter.sh @@ -22,5 +22,5 @@ fi ######################### export RUN_LOCAL=true -# shellcheck disable=SC1091,SC1090 +# shellcheck source=../lib/linter.sh source "$PWD"/lib/linter.sh diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index dde4c70c..0f011b3b 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -# shellcheck disable=SC2034 ################################################################################ ################################################################################ @@ -56,8 +55,7 @@ function BuildFileList() ################################################# # Get the Array of files changed in the commits # ################################################# - # shellcheck disable=SC2207 - RAW_FILE_ARRAY=($(cd "$GITHUB_WORKSPACE" || exit; git diff --name-only "$DEFAULT_BRANCH..$GITHUB_SHA" --diff-filter=d 2>&1)) + mapfile -t RAW_FILE_ARRAY < <(git -C "$GITHUB_WORKSPACE" diff --name-only "$DEFAULT_BRANCH..$GITHUB_SHA" --diff-filter=d 2>&1) ####################### # Load the error code # @@ -413,6 +411,8 @@ function BuildFileList() fi done + echo $READ_ONLY_CHANGE_FLAG > /dev/null 2>&1 || true # Workaround SC2034 + ######################################### # Need to switch back to branch of code # ######################################### diff --git a/lib/linter.sh b/lib/linter.sh index 0c2287ad..069a55e2 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -9,8 +9,11 @@ ######################### # Source Function Files # ######################### +# shellcheck source=../lib/buildFileList.sh source /action/lib/buildFileList.sh # Source the function script(s) +# shellcheck source=../lib/validation.sh source /action/lib/validation.sh # Source the function script(s) +# shellcheck source=../lib/worker.sh source /action/lib/worker.sh # Source the function script(s) ########### @@ -146,15 +149,10 @@ DEFAULT_IFS="$IFS" # Get the Default IFS for updating ############################################################### # Default Vars that are called in Subs and need to be ignored # ############################################################### -# shellcheck disable=SC2034 DEFAULT_DISABLE_ERRORS='false' # Default to enabling errors -# shellcheck disable=SC2034 RAW_FILE_ARRAY=() # Array of all files that were changed -# shellcheck disable=SC2034 READ_ONLY_CHANGE_FLAG=0 # Flag set to 1 if files changed are not txt or md -# shellcheck disable=SC2034 TEST_CASE_FOLDER='.automation/test' # Folder for test cases we should always ignore -# shellcheck disable=SC2034 DEFAULT_ANSIBLE_DIRECTORY="$GITHUB_WORKSPACE/ansible" # Default Ansible Directory ########################## @@ -1103,8 +1101,7 @@ if [ "$VALIDATE_OPENAPI" == "true" ]; then ############################################################################### IFS=$'\n' - # shellcheck disable=SC2207 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1)) + mapfile -t LIST_FILES < <(find "$GITHUB_WORKSPACE" -type f -regex ".*\.\(yml\|yaml\|json\)\$" 2>&1) for FILE in "${LIST_FILES[@]}" do if DetectOpenAPIFile "$FILE"; then diff --git a/lib/worker.sh b/lib/worker.sh index 287215dc..70ffc4e9 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -38,7 +38,6 @@ function LintCodebase() ####################################### # Validate we have jsonlint installed # ####################################### - # shellcheck disable=SC2230 VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1) ####################### @@ -91,8 +90,7 @@ function LintCodebase() ################################# # Get list of all files to lint # ################################# - # shellcheck disable=SC2207,SC2086 - LIST_FILES=($(cd "$GITHUB_WORKSPACE" || exit; find . -type f -regex "$FILE_EXTENSIONS" 2>&1)) + mapfile -t LIST_FILES < <(find "$GITHUB_WORKSPACE" -type f -regex "$FILE_EXTENSIONS" 2>&1) ########################### # Set IFS back to default # @@ -229,7 +227,6 @@ function TestCodebase() ##################################### # Validate we have linter installed # ##################################### - # shellcheck disable=SC2230 VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1) ####################### @@ -263,8 +260,7 @@ function TestCodebase() ################################# # Get list of all files to lint # ################################# - # shellcheck disable=SC2207,SC2086,SC2010 - LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; ls ansible/ | grep ".yml" 2>&1)) + mapfile -t LIST_FILES < <(ls "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/ansible/*.yml" 2>&1) else ############################################################################### # Set the file seperator to newline to allow for grabbing objects with spaces # @@ -274,8 +270,7 @@ function TestCodebase() ################################# # Get list of all files to lint # ################################# - # shellcheck disable=SC2207,SC2086 - LIST_FILES=($(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; find "$INDVIDUAL_TEST_FOLDER" -type f -regex "$FILE_EXTENSIONS" ! -path "*./ansible*" 2>&1)) + mapfile -t LIST_FILES < <(find "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/$INDVIDUAL_TEST_FOLDER" -type f -regex "$FILE_EXTENSIONS" ! -path "*./ansible*" 2>&1) ########################### # Set IFS back to default # @@ -505,7 +500,6 @@ function LintAnsibleFiles() ########################################### # Validate we have ansible-lint installed # ########################################### - # shellcheck disable=SC2230 VALIDATE_INSTALL_CMD=$(command -v "$LINTER_NAME" 2>&1) ####################### @@ -551,14 +545,12 @@ function LintAnsibleFiles() if [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then # We need to only check the ansible playbooks that have updates #LIST_FILES=("${ANSIBLE_ARRAY[@]}") - # shellcheck disable=SC2164,SC2010,SC2207 - LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1)) + mapfile -t LIST_FILES < <(ls "$ANSIBLE_DIRECTORY/*.yml" 2>&1) else ################################# # Get list of all files to lint # ################################# - # shellcheck disable=SC2164,SC2010,SC2207 - LIST_FILES=($(cd "$ANSIBLE_DIRECTORY"; ls | grep ".yml" 2>&1)) + mapfile -t LIST_FILES < <(ls "$ANSIBLE_DIRECTORY/*.yml" 2>&1) fi ###############################################################