diff --git a/.automation/cleanup-docker.sh b/.automation/cleanup-docker.sh index ba2cb758..131daf6a 100755 --- a/.automation/cleanup-docker.sh +++ b/.automation/cleanup-docker.sh @@ -115,9 +115,9 @@ ValidateInput() # Check if we need to get the name of the branch # ################################################## if [[ "$IMAGE_VERSION" != "latest" ]]; then - ################################### - # Remove non alpha-numberic chars # - ################################### + ################################## + # Remove non alpha-numeric chars # + ################################## IMAGE_VERSION=$(echo "$IMAGE_VERSION" | tr -cd '[:alnum:]') else ############################################# diff --git a/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml b/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml index f6f08485..0c73fc94 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/collectd-settings.yml @@ -42,9 +42,9 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## - name: Setup Grafana # yamllint disable shell: curl --fail -Lk \ diff --git a/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml b/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml index 91865d3c..d44e2101 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/ghe-initial-configuration.yml @@ -57,10 +57,10 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### - - name: Setup License, Admin Password, and Initial Setttings + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## + - name: Setup License, Admin Password, and Initial Settings command: curl --fail -Lk \ -X POST "https://{{ ansible_host }}:8443/setup/api/start" \ -F license=@/tmp/ghe-license.ghl \ diff --git a/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml b/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml index 33919111..aaaa0780 100644 --- a/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml +++ b/.automation/test/ansible/ghe-initialize/tasks/splunk-settings.yml @@ -42,9 +42,9 @@ group: admin mode: 0644 - ######################################################### - # Set up Admin password, License, and Initial Setttings # - ######################################################### + ######################################################## + # Set up Admin password, License, and Initial Settings # + ######################################################## - name: Setup Splunk # yamllint disable shell: curl --fail -Lk \ diff --git a/.automation/test/coffeescript/coffeescript_bad_1.coffee b/.automation/test/coffeescript/coffeescript_bad_1.coffee index 624cb3cd..5efeeacb 100644 --- a/.automation/test/coffeescript/coffeescript_bad_1.coffee +++ b/.automation/test/coffeescript/coffeescript_bad_1.coffee @@ -60,7 +60,7 @@ module.exports = (robot) -> ) # Drop the hammer # ################### robot.respond /drop the hammer/i, (msg) -> - msg.send "Commmencing the hammer dropping..." + msg.send "Commencing the hammer dropping..." msg.send msg.random dropHammer ############### diff --git a/.automation/test/coffeescript/coffeescript_good_1.coffee b/.automation/test/coffeescript/coffeescript_good_1.coffee index 40bc1264..62f2a4fe 100644 --- a/.automation/test/coffeescript/coffeescript_good_1.coffee +++ b/.automation/test/coffeescript/coffeescript_good_1.coffee @@ -62,7 +62,7 @@ module.exports = (robot) -> # Drop the hammer # ################### robot.respond /drop the hammer/i, (msg) -> - msg.send "Commmencing the hammer dropping..." + msg.send "Commencing the hammer dropping..." msg.send msg.random dropHammer ############### diff --git a/.automation/test/javascript/javascript_bad_1.js b/.automation/test/javascript/javascript_bad_1.js index 0ed075fc..98e5ee29 100644 --- a/.automation/test/javascript/javascript_bad_1.js +++ b/.automation/test/javascript/javascript_bad_1.js @@ -7,7 +7,7 @@ var userArray = [ 'user1' ] here is some garbage = that var teamDescription = Team of Robots -var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here +var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here var teamName = process.env.GHES_TEAM_NAME var teamAccess = 'pull' // pull,push,admin options here diff --git a/.automation/test/javascript/javascript_good_1.js b/.automation/test/javascript/javascript_good_1.js index 09417a6b..ad32089f 100644 --- a/.automation/test/javascript/javascript_good_1.js +++ b/.automation/test/javascript/javascript_good_1.js @@ -5,7 +5,7 @@ var handler = createHandler({ path: '/webhook', secret: (process.env.SECRET) }) var userArray = ['user1'] var teamDescription = 'Team of Robots' -var teamPrivacy = 'closed' // closed (visibile) / secret (hidden) are options here +var teamPrivacy = 'closed' // closed (visible) / secret (hidden) are options here var teamName = process.env.GHES_TEAM_NAME var teamAccess = 'pull' // pull,push,admin options here diff --git a/.automation/test/kotlin/README.md b/.automation/test/kotlin/README.md new file mode 100644 index 00000000..f1fd9cfe --- /dev/null +++ b/.automation/test/kotlin/README.md @@ -0,0 +1,13 @@ +# Kotlin Test Cases +This folder holds the test cases for **Kotlin**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/kotlin/kotlin_bad_1.kt b/.automation/test/kotlin/kotlin_bad_1.kt new file mode 100644 index 00000000..ad02ddc8 --- /dev/null +++ b/.automation/test/kotlin/kotlin_bad_1.kt @@ -0,0 +1,6 @@ +fun main() { + val n = "World"; + val v = "Hello, ${n}!"; + + println(v); +} \ No newline at end of file diff --git a/.automation/test/kotlin/kotlint_good_1.kt b/.automation/test/kotlin/kotlint_good_1.kt new file mode 100644 index 00000000..6e1f1a51 --- /dev/null +++ b/.automation/test/kotlin/kotlint_good_1.kt @@ -0,0 +1,6 @@ +fun main() { + val n = "World" + val v = "Hello, $n!" + + println(v) +} diff --git a/.automation/test/php/README.md b/.automation/test/php/README.md new file mode 100644 index 00000000..7ab89f43 --- /dev/null +++ b/.automation/test/php/README.md @@ -0,0 +1,13 @@ +# PHP Test Cases +This folder holds the test cases for **PHP**. + +## Additional Docs +No Additional information is needed for this test case. + +## Good Test Cases +The test cases denoted: `LANGUAGE_good_FILE.EXTENSION` are all valid, and should pass successfully when linted. +- **Note:** They are linted utilizing the default linter rules. + +## Bad Test Cases +The test cases denoted: `LANGUAGE_bad_FILE.EXTENSION` are **NOT** valid, and should trigger errors when linted. +- **Note:** They are linted utilizing the default linter rules. diff --git a/.automation/test/php/php_bad_1.php b/.automation/test/php/php_bad_1.php new file mode 100644 index 00000000..e564fc66 --- /dev/null +++ b/.automation/test/php/php_bad_1.php @@ -0,0 +1,3 @@ + @@ -303,6 +305,23 @@ Here is more data -------------------------------------------------------------------------------- +## PHP +- [PHP](https://www.php.net/) + +### PHP Config file +- There is no top level *configuration file* available at this time + +### PHP disable single line +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable code block +- There is currently **No** way to disable rules inline of the file(s) + +### PHP disable entire file +- There is currently **No** way to disable rules inline of the file(s) + +-------------------------------------------------------------------------------- + ## XML - [XML](http://xmlsoft.org/) @@ -564,3 +583,27 @@ a {} ### dotenv-linter disable entire file - There is currently **No** way to disable rules inline of the file(s) + +-------------------------------------------------------------------------------- + +## Kotlin +- [ktlint](https://github.com/pinterest/ktlint) + +### ktlint Config file +- There is no top level *configuration file* available at this time + +### ktlint disable single line +```kotlin +import package.* // ktlint-disable no-wildcard-imports +``` + +### ktlint disable code block +```kotlin +/* ktlint-disable no-wildcard-imports */ +import package.a.* +import package.b.* +/* ktlint-enable no-wildcard-imports */ +``` + +### ktlint disable entire file +- There is currently **No** way to disable rules inline of the file(s) diff --git a/lib/linter.sh b/lib/linter.sh index 9c9ec2f5..65047ade 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -32,7 +32,7 @@ COFFEESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$COFFEE_FILE_NAME" # Path to JAVASCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file JAVASCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$JAVASCRIPT_FILE_NAME" # Path to the Javascript lint rules JAVASCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard -# Typecript Vars +# Typescript Vars TYPESCRIPT_FILE_NAME='.eslintrc.yml' # Name of the file TYPESCRIPT_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TYPESCRIPT_FILE_NAME" # Path to the Typescript lint rules TYPESCRIPT_STANDARD_LINTER_RULES='' # ENV string to pass when running js standard @@ -48,25 +48,28 @@ GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to th # Terraform Vars TERRAFORM_FILE_NAME='.tflint.hcl' # Name of the file TERRAFORM_LINTER_RULES="$DEFAULT_RULES_LOCATION/$TERRAFORM_FILE_NAME" # Path to the Terraform lint rules +# Powershell Vars +POWERSHELL_FILE_NAME='.powershell-psscriptanalyzer.psd1' # Name of the file +POWERSHELL_LINTER_RULES="$DEFAULT_RULES_LOCATION/$POWERSHELL_FILE_NAME" # Path to the Powershell lint rules # CSS Vars CSS_FILE_NAME='.stylelintrc.json' # Name of the file CSS_LINTER_RULES="$DEFAULT_RULES_LOCATION/$CSS_FILE_NAME" # Path to the CSS lint rules - ####################################### # Linter array for information prints # ####################################### LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "/dockerfilelint/bin/dockerfilelint" "golangci-lint" "tflint" - "stylelint" "dotenv-linter") + "stylelint" "dotenv-linter" "powershell" "ktlint") ############################# # Language array for prints # ############################# -LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RUBY' 'PYTHON' +LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'PHP' 'RUBY' 'PYTHON' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' - 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' "ENV") + 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' + 'ENV' 'POWERSHELL' 'KOTLIN') ################### # GitHub ENV Vars # @@ -83,6 +86,7 @@ VALIDATE_XML="${VALIDATE_XML}" # Boolean to validate lang VALIDATE_MD="${VALIDATE_MD}" # Boolean to validate language VALIDATE_BASH="${VALIDATE_BASH}" # Boolean to validate language VALIDATE_PERL="${VALIDATE_PERL}" # Boolean to validate language +VALIDATE_PHP="${VALIDATE_PHP}" # Boolean to validate language VALIDATE_PYTHON="${VALIDATE_PYTHON}" # Boolean to validate language VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language VALIDATE_COFFEE="${VALIDATE_COFFEE}" # Boolean to validate language @@ -91,11 +95,13 @@ VALIDATE_JAVASCRIPT_ES="${VALIDATE_JAVASCRIPT_ES}" # Boolean to val VALIDATE_JAVASCRIPT_STANDARD="${VALIDATE_JAVASCRIPT_STANDARD}" # Boolean to validate language VALIDATE_TYPESCRIPT_ES="${VALIDATE_TYPESCRIPT_ES}" # Boolean to validate language VALIDATE_TYPESCRIPT_STANDARD="${VALIDATE_TYPESCRIPT_STANDARD}" # Boolean to validate language -VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language -VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language -VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language -VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language -VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_DOCKER="${VALIDATE_DOCKER}" # Boolean to validate language +VALIDATE_GO="${VALIDATE_GO}" # Boolean to validate language +VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language +VALIDATE_POWERSHELL="${VALIDATE_POWERSHELL}" # Boolean to validate language +VALIDATE_CSS="${VALIDATE_CSS}" # Boolean to validate language +VALIDATE_ENV="${VALIDATE_ENV}" # Boolean to validate language +VALIDATE_KOTLIN="${VALIDATE_KOTLIN}" # Boolean to validate language TEST_CASE_RUN="${TEST_CASE_RUN}" # Boolean to validate only test cases DISABLE_ERRORS="${DISABLE_ERRORS}" # Boolean to enable warning-only output without throwing errors LINTER_RULES_PATH="${LINTER_RULES_PATH:-.github/linters}" # Linter Path Directory @@ -129,6 +135,7 @@ FILE_ARRAY_XML=() # Array of files to check FILE_ARRAY_MD=() # Array of files to check FILE_ARRAY_BASH=() # Array of files to check FILE_ARRAY_PERL=() # Array of files to check +FILE_ARRAY_PHP=() # Array of files to check FILE_ARRAY_RUBY=() # Array of files to check FILE_ARRAY_PYTHON=() # Array of files to check FILE_ARRAY_COFFEESCRIPT=() # Array of files to check @@ -139,8 +146,10 @@ FILE_ARRAY_TYPESCRIPT_STANDARD=() # Array of files to check FILE_ARRAY_DOCKER=() # Array of files to check FILE_ARRAY_GO=() # Array of files to check FILE_ARRAY_TERRAFORM=() # Array of files to check +FILE_ARRAY_POWERSHELL=() # Array of files to check FILE_ARRAY_CSS=() # Array of files to check FILE_ARRAY_ENV=() # Array of files to check +FILE_ARRAY_KOTLIN=() # Array of files to check ############ # Counters # @@ -151,6 +160,7 @@ ERRORS_FOUND_XML=0 # Count of errors found ERRORS_FOUND_MARKDOWN=0 # Count of errors found ERRORS_FOUND_BASH=0 # Count of errors found ERRORS_FOUND_PERL=0 # Count of errors found +ERRORS_FOUND_PHP=0 # Count of errors found ERRORS_FOUND_RUBY=0 # Count of errors found ERRORS_FOUND_PYTHON=0 # Count of errors found ERRORS_FOUND_COFFEESCRIPT=0 # Count of errors found @@ -162,8 +172,10 @@ ERRORS_FOUND_TYPESCRIPT_ES=0 # Count of errors found ERRORS_FOUND_DOCKER=0 # Count of errors found ERRORS_FOUND_GO=0 # Count of errors found ERRORS_FOUND_TERRAFORM=0 # Count of errors found +ERRORS_FOUND_POWERSHELL=0 # Count of errors found ERRORS_FOUND_CSS=0 # Count of errors found ERRORS_FOUND_ENV=0 # Count of errors found +ERRORS_FOUND_KOTLIN=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -224,7 +236,7 @@ GetLinterVersions() ############################## # Check the shell for errors # ############################## - if [ $ERROR_CODE -ne 0 ] | [ -z "${GET_VERSION_CMD[*]}" ]; then + if [ $ERROR_CODE -ne 0 ] || [ -z "${GET_VERSION_CMD[*]}" ]; then echo "WARN! Failed to get version info for:[$LINTER]" echo "---------------------------------------------" else @@ -355,9 +367,9 @@ GetStandardRules() ENV_STRING+="--env ${ENV} " done - ######################################## - # Remove trailing and ending witespace # - ######################################## + ######################################### + # Remove trailing and ending whitespace # + ######################################### if [[ "$LINTER" == "javascript" ]]; then JAVASCRIPT_STANDARD_LINTER_RULES="$(echo -e "${ENV_STRING}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')" elif [[ "$LINTER" == "typescript" ]]; then @@ -729,6 +741,7 @@ GetValidationInfo() VALIDATE_MD=$(echo "$VALIDATE_MD" | awk '{print tolower($0)}') VALIDATE_BASH=$(echo "$VALIDATE_BASH" | awk '{print tolower($0)}') VALIDATE_PERL=$(echo "$VALIDATE_PERL" | awk '{print tolower($0)}') + VALIDATE_PHP=$(echo "$VALIDATE_PHP" | awk '{print tolower($0)}') VALIDATE_PYTHON=$(echo "$VALIDATE_PYTHON" | awk '{print tolower($0)}') VALIDATE_RUBY=$(echo "$VALIDATE_RUBY" | awk '{print tolower($0)}') VALIDATE_COFFEE=$(echo "$VALIDATE_COFFEE" | awk '{print tolower($0)}') @@ -740,8 +753,10 @@ GetValidationInfo() VALIDATE_DOCKER=$(echo "$VALIDATE_DOCKER" | awk '{print tolower($0)}') VALIDATE_GO=$(echo "$VALIDATE_GO" | awk '{print tolower($0)}') VALIDATE_TERRAFORM=$(echo "$VALIDATE_TERRAFORM" | awk '{print tolower($0)}') + VALIDATE_POWERSHELL=$(echo "$VALIDATE_POWERSHELL" | awk '{print tolower($0)}') VALIDATE_CSS=$(echo "$VALIDATE_CSS" | awk '{print tolower($0)}') VALIDATE_ENV=$(echo "$VALIDATE_ENV" | awk '{print tolower($0)}') + VALIDATE_KOTLIN=$(echo "$VALIDATE_KOTLIN" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -753,6 +768,7 @@ GetValidationInfo() -n "$VALIDATE_MD" || \ -n "$VALIDATE_BASH" || \ -n "$VALIDATE_PERL" || \ + -n "$VALIDATE_PHP" || \ -n "$VALIDATE_PYTHON" || \ -n "$VALIDATE_RUBY" || \ -n "$VALIDATE_COFFEE" || \ @@ -764,8 +780,10 @@ GetValidationInfo() -n "$VALIDATE_DOCKER" || \ -n "$VALIDATE_GO" || \ -n "$VALIDATE_TERRAFORM" || \ + -n "$VALIDATE_POWERSHELL" || \ -n "$VALIDATE_CSS" || \ - -n "$VALIDATE_ENV" ]]; then + -n "$VALIDATE_ENV" || \ + -n "$VALIDATE_KOTLIN" ]]; then ANY_SET="true" fi @@ -853,6 +871,20 @@ GetValidationInfo() VALIDATE_PERL="true" fi + #################################### + # Validate if we should check PHP # + #################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_PHP" ]]; then + # PHP flag was not set - default to false + VALIDATE_PHP="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_PHP="true" + fi + ###################################### # Validate if we should check PYTHON # ###################################### @@ -1007,6 +1039,20 @@ GetValidationInfo() VALIDATE_TERRAFORM="true" fi + ######################################### + # Validate if we should check POWERSHELL # + ######################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_POWERSHELL" ]]; then + # POWERSHELL flag was not set - default to false + VALIDATE_POWERSHELL="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_POWERSHELL="true" + fi + ################################### # Validate if we should check CSS # ################################### @@ -1021,9 +1067,9 @@ GetValidationInfo() VALIDATE_CSS="true" fi - #################################### + ################################### # Validate if we should check ENV # - #################################### + ################################### if [[ "$ANY_SET" == "true" ]]; then # Some linter flags were set - only run those set to true if [[ -z "$VALIDATE_ENV" ]]; then @@ -1035,6 +1081,21 @@ GetValidationInfo() VALIDATE_ENV="true" fi + ###################################### + # Validate if we should check KOTLIN # + ###################################### + if [[ "$ANY_SET" == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z "$VALIDATE_KOTLIN" ]]; then + # ENV flag was not set - default to false + VALIDATE_KOTLIN="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_KOTLIN="true" + fi + + ####################################### # Print which linters we are enabling # ####################################### @@ -1068,6 +1129,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [PERL] files in code base...") fi + if [[ "$VALIDATE_PHP" == "true" ]]; then + PRINT_ARRAY+=("- Validating [PHP] files in code base...") + else + PRINT_ARRAY+=("- Excluding [PHP] files in code base...") + fi if [[ "$VALIDATE_PYTHON" == "true" ]]; then PRINT_ARRAY+=("- Validating [PYTHON] files in code base...") else @@ -1123,6 +1189,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [TERRAFORM] files in code base...") fi + if [[ "$VALIDATE_POWERSHELL" == "true" ]]; then + PRINT_ARRAY+=("- Validating [POWERSHELL] files in code base...") + else + PRINT_ARRAY+=("- Excluding [POWERSHELL] files in code base...") + fi if [[ "$VALIDATE_CSS" == "true" ]]; then PRINT_ARRAY+=("- Validating [CSS] files in code base...") else @@ -1133,6 +1204,11 @@ GetValidationInfo() else PRINT_ARRAY+=("- Excluding [ENV] files in code base...") fi + if [[ "$VALIDATE_KOTLIN" == "true" ]]; then + PRINT_ARRAY+=("- Validating [KOTLIN] files in code base...") + else + PRINT_ARRAY+=("- Excluding [KOTLIN] files in code base...") + fi ############################## # Validate Ansible Directory # @@ -1262,9 +1338,9 @@ BuildFileList() echo "Generating Diff with:[git diff --name-only '$DEFAULT_BRANCH..$GITHUB_SHA' --diff-filter=d]" fi - ################################################ - # Get the Array of files changed in the comits # - ################################################ + ################################################# + # 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)) @@ -1283,9 +1359,9 @@ BuildFileList() exit 1 fi - ################################################# - # Itterate through the array of all files found # - ################################################# + ################################################ + # Iterate through the array of all files found # + ################################################ echo "" echo "----------------------------------------------" echo "Files that have been modified in the commit(s):" @@ -1377,6 +1453,18 @@ BuildFileList() ########################################################## READ_ONLY_CHANGE_FLAG=1 ###################### + # Get the PHP files # + ###################### + elif [ "$FILE_TYPE" == "php" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_PHP+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 + ###################### # Get the RUBY files # ###################### elif [ "$FILE_TYPE" == "rb" ]; then @@ -1462,6 +1550,14 @@ BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + ########################### + # Get the Powershell files # + ########################### + elif [ "$FILE_TYPE" == "ps1" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_POWERSHELL+=("$FILE") elif [ "$FILE_TYPE" == "css" ]; then ################################ # Append the file to the array # @@ -1480,6 +1576,15 @@ BuildFileList() # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "kt" ] || [ "$FILE_TYPE" == "kts" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_KOTLIN+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 elif [ "$FILE" == "Dockerfile" ]; then ################################ # Append the file to the array # @@ -1637,7 +1742,7 @@ LintCodebase() if [ ${#FILE_ARRAY[@]} -eq 0 ] && [ "$VALIDATE_ALL_CODEBASE" == "false" ]; then # No files found in commit and user has asked to not validate code base SKIP_FLAG=1 - # echo " - No files found in chageset to lint for language:[$FILE_TYPE]" + # echo " - No files found in changeset to lint for language:[$FILE_TYPE]" elif [ ${#FILE_ARRAY[@]} -ne 0 ]; then # We have files added to array of files to check LIST_FILES=("${FILE_ARRAY[@]}") # Copy the array into list @@ -1705,10 +1810,26 @@ LintCodebase() echo "---------------------------" echo "File:[$FILE]" - ################################ - # Lint the file with the rules # - ################################ - LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + #################### + # Set the base Var # + #################### + LINT_CMD='' + + ####################################### + # Corner case for Powershell subshell # + ####################################### + if [[ "$FILE_TYPE" == "POWERSHELL" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1) + else + ################################ + # Lint the file with the rules # + ################################ + LINT_CMD=$(cd "$GITHUB_WORKSPACE" || exit; $LINTER_COMMAND "$FILE" 2>&1) + fi ####################### # Load the error code # @@ -1875,6 +1996,12 @@ TestCodebase() # Lint the file with the rules # ################################ LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER/ansible" || exit; $LINTER_COMMAND "$FILE" 2>&1) + elif [[ "$FILE_TYPE" == "POWERSHELL" ]]; then + ################################ + # Lint the file with the rules # + ################################ + # Need to append "'" to make the pwsh call syntax correct, also exit with exit code from inner subshell + LINT_CMD=$(cd "$GITHUB_WORKSPACE/$TEST_CASE_FOLDER" || exit; $LINTER_COMMAND "$FILE"; exit $? 2>&1) else ################################ # Lint the file with the rules # @@ -1981,6 +2108,7 @@ Footer() [ "$ERRORS_FOUND_MARKDOWN" -ne 0 ] || \ [ "$ERRORS_FOUND_BASH" -ne 0 ] || \ [ "$ERRORS_FOUND_PERL" -ne 0 ] || \ + [ "$ERRORS_FOUND_PHP" -ne 0 ] || \ [ "$ERRORS_FOUND_PYTHON" -ne 0 ] || \ [ "$ERRORS_FOUND_COFFEESCRIPT" -ne 0 ] || \ [ "$ERRORS_FOUND_ANSIBLE" -ne 0 ] || \ @@ -1991,9 +2119,11 @@ Footer() [ "$ERRORS_FOUND_DOCKER" -ne 0 ] || \ [ "$ERRORS_FOUND_GO" -ne 0 ] || \ [ "$ERRORS_FOUND_TERRAFORM" -ne 0 ] || \ + [ "$ERRORS_FOUND_POWERSHELL" -ne 0 ] || \ [ "$ERRORS_FOUND_RUBY" -ne 0 ] || \ [ "$ERRORS_FOUND_CSS" -ne 0 ] || \ - [ "$ERRORS_FOUND_ENV" -ne 0 ]; then + [ "$ERRORS_FOUND_ENV" -ne 0 ] || \ + [ "$ERRORS_FOUND_KOTLIN" -ne 0 ]; then # Failed exit echo "Exiting with errors found!" exit 1 @@ -2019,7 +2149,7 @@ RunTestCases() # version of linter.sh, and a new container is built with the latest codebase # for testing. That container is spun up, and ran, # with the flag: TEST_CASE_RUN=true - # So that the new code can be validated againt the test cases + # So that the new code can be validated against the test cases ################# # Header prints # @@ -2040,6 +2170,7 @@ RunTestCases() TestCodebase "BASH" "shellcheck" "shellcheck" ".*\.\(sh\)\$" TestCodebase "PYTHON" "pylint" "pylint --rcfile $PYTHON_LINTER_RULES -E" ".*\.\(py\)\$" TestCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" + TestCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" TestCodebase "RUBY" "rubocop" "rubocop -c $RUBY_LINTER_RULES" ".*\.\(rb\)\$" TestCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$" TestCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f $COFFEESCRIPT_LINTER_RULES" ".*\.\(coffee\)\$" @@ -2050,8 +2181,10 @@ RunTestCases() TestCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" TestCodebase "ANSIBLE" "ansible-lint" "ansible-lint -v -c $ANSIBLE_LINTER_RULES" "ansible-lint" TestCodebase "TERRAFORM" "tflint" "tflint -c $TERRAFORM_LINTER_RULES" ".*\.\(tf\)\$" + TestCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" TestCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" + TestCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" ################# # Footer prints # @@ -2076,9 +2209,9 @@ Header # needed to connect back and update checks GetGitHubVars -########################################## -# Get the langugages we need to validate # -########################################## +######################################### +# Get the languages we need to validate # +######################################### GetValidationInfo ######################## @@ -2106,6 +2239,8 @@ GetLinterRules "$GO_FILE_NAME" "$GO_LINTER_RULES" GetLinterRules "$DOCKER_FILE_NAME" "$DOCKER_LINTER_RULES" # Get Terraform rules GetLinterRules "$TERRAFORM_FILE_NAME" "$TERRAFORM_LINTER_RULES" +# Get PowerShell rules +GetLinterRules "$POWERSHELL_FILE_NAME" "$POWERSHELL_LINTER_RULES" # Get CSS rules GetLinterRules "$CSS_FILE_NAME" "$CSS_LINTER_RULES" @@ -2217,6 +2352,17 @@ if [ "$VALIDATE_PERL" == "true" ]; then LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" fi +################ +# PHP LINTING # +################ +if [ "$VALIDATE_PHP" == "true" ]; then + ####################### + # Lint the PHP files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PHP" "php" "php -l" ".*\.\(php\)\$" "${FILE_ARRAY_PHP[@]}" +fi + ################ # RUBY LINTING # ################ @@ -2337,15 +2483,26 @@ if [ "$VALIDATE_CSS" == "true" ]; then LintCodebase "CSS" "stylelint" "stylelint --config $CSS_LINTER_RULES" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" fi -################ +############### # ENV LINTING # -################ +############### if [ "$VALIDATE_ENV" == "true" ]; then ####################### # Lint the env files # ####################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "${FILE_ARRAY_ENV[@]}" + LintCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\).*\$" "${FILE_ARRAY_ENV[@]}" +fi + +################## +# KOTLIN LINTING # +################## +if [ "$VALIDATE_KOTLIN" == "true" ]; then + ####################### + # Lint the Kotlin files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "KOTLIN" "ktlint" "ktlint" ".*\.\(kt\|kts\)\$" "${FILE_ARRAY_ENV[@]}" fi ################## @@ -2359,6 +2516,17 @@ if [ "$VALIDATE_DOCKER" == "true" ]; then LintCodebase "DOCKER" "/dockerfilelint/bin/dockerfilelint" "/dockerfilelint/bin/dockerfilelint" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" fi +###################### +# POWERSHELL LINTING # +###################### +if [ "$VALIDATE_POWERSHELL" == "true" ]; then + ############################# + # Lint the powershell files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "POWERSHELL" "pwsh" "pwsh -c Invoke-ScriptAnalyzer -EnableExit -Settings $POWERSHELL_LINTER_RULES -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" +fi + ########## # Footer # ##########