From afe4f087cbe98a614b5a63b6865a901c5e5e445e Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 14 Jul 2020 09:28:58 -0500 Subject: [PATCH 1/8] Adding groovy --- .automation/test/groovy/README.md | 13 +++++++ .automation/test/groovy/groovy_bad_01.groovy | 6 +++ .automation/test/groovy/groovy_good_01.groovy | 6 +++ README.md | 6 ++- dependencies/package.json | 3 +- docs/disabling-linters.md | 39 +++++++++++++++++++ lib/buildFileList.sh | 9 +++++ lib/linter.sh | 24 +++++++++++- lib/validation.sh | 21 ++++++++++ lib/worker.sh | 1 + 10 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 .automation/test/groovy/README.md create mode 100644 .automation/test/groovy/groovy_bad_01.groovy create mode 100644 .automation/test/groovy/groovy_good_01.groovy diff --git a/.automation/test/groovy/README.md b/.automation/test/groovy/README.md new file mode 100644 index 00000000..b08a3b4f --- /dev/null +++ b/.automation/test/groovy/README.md @@ -0,0 +1,13 @@ +# Groovy Test Cases +This folder holds the test cases for **Groovy**. + +## 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/groovy/groovy_bad_01.groovy b/.automation/test/groovy/groovy_bad_01.groovy new file mode 100644 index 00000000..7d071754 --- /dev/null +++ b/.automation/test/groovy/groovy_bad_01.groovy @@ -0,0 +1,6 @@ +class Example { + static void main(String[] args) + File file = new File("E:/Example.txt") + The file ${file.absolutePath} has ${file.length()} bytes" + } +} diff --git a/.automation/test/groovy/groovy_good_01.groovy b/.automation/test/groovy/groovy_good_01.groovy new file mode 100644 index 00000000..d0375dab --- /dev/null +++ b/.automation/test/groovy/groovy_good_01.groovy @@ -0,0 +1,6 @@ +class Example { + static void main(String[] args) { + File file = new File("E:/Example.txt") + println "The file ${file.absolutePath} has ${file.length()} bytes" + } +} diff --git a/README.md b/README.md index 1593506c..eaef2b86 100644 --- a/README.md +++ b/README.md @@ -40,10 +40,11 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **Clojure** | [clj-kondo](https://github.com/borkdude/clj-kondo) | | **CoffeeScript** | [coffeelint](https://coffeelint.github.io/) | | **Dockerfile** | [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) | -| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | +| **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | | **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | | **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | -| **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | +| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | +| **HTML** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) | | **Kotlin** | [ktlint](https://github.com/pinterest/ktlint) | @@ -177,6 +178,7 @@ and won't run anything unexpected. | **VALIDATE_TYPESCRIPT_STANDARD** | `true` | Flag to enable or disable the linting process of the language. (Utilizing: standard) | | **VALIDATE_DOCKER** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_GO** | `true` | Flag to enable or disable the linting process of the language. | +| **VALIDATE_GROOVY** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_POWERSHELL** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_ARM** | `true` | Flag to enable or disable the linting process of the language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the language. | diff --git a/dependencies/package.json b/dependencies/package.json index e5a2934d..76182dbd 100644 --- a/dependencies/package.json +++ b/dependencies/package.json @@ -18,6 +18,7 @@ "standard": "^14.3.4", "stylelint": "^13.6.1", "stylelint-config-standard": "^20.0.0", - "typescript": "^3.9.6" + "typescript": "^3.9.6", + "npm-groovy-lint": "^5.5.0" } } diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index fb622005..4c50972d 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -30,6 +30,7 @@ For some linters it is also possible to override rules on a case by case level w - [Typescript Eslint](#typescript-eslint) - [Typescript Standard](#typescript-standard) - [Golang](#golang) +- [Groovy](#groovy) - [Dockerfile](#dockerfile) - [Terraform](#terraform) - [CSS](#css) @@ -563,6 +564,44 @@ alert('foo') -------------------------------------------------------------------------------- +## Groovy +- [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) + +### groovy-lint standard Config file +- `.github/linters/.groovylintrc.json` +- You can pass multiple rules and overwrite default rules +- File should be located at: `.github/linters/.groovylintrc.json` + +### groovy-lint disable single line +```groovy +def variable = 1; // groovylint-disable-line + +// groovylint-disable-next-line +def variable = 1; + +/* groovylint-disable-next-line */ +def variable = 1; + +def variable = 1; /* groovylint-disable-line */ +``` + +### groovy-lint disable code block +```groovy +/* groovylint-disable */ + +def variable = 1; + +/* groovylint-enable */ +``` + +### groovy-lint disable entire file +- At the top line of the file add the line: +```groovy +/* groovylint-disable */ +``` + +-------------------------------------------------------------------------------- + ## Dockerfile - [dockerfilelint](https://github.com/replicatedhq/dockerfilelint.git) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 06f0110f..965bb6b9 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -421,6 +421,15 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 + elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ]; then + ################################ + # Append the file to the array # + ################################ + FILE_ARRAY_GROOVY+=("$FILE") + ########################################################## + # Set the READ_ONLY_CHANGE_FLAG since this could be exec # + ########################################################## + READ_ONLY_CHANGE_FLAG=1 else ############################################## # Use file to see if we can parse what it is # diff --git a/lib/linter.sh b/lib/linter.sh index 324084be..15424722 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -59,6 +59,9 @@ DOCKER_LINTER_RULES="$DEFAULT_RULES_LOCATION/$DOCKER_FILE_NAME" # Path t # Golang Vars GO_FILE_NAME='.golangci.yml' # Name of the file GO_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GO_FILE_NAME" # Path to the Go lint rules +# Groovy Vars +GROOVY_FILE_NAME='.groovylintrc.json' # Name of the file +GROOVY_LINTER_RULES="$DEFAULT_RULES_LOCATION/$GROOVY_FILE_NAME" # Path to the Go lint rules # 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 @@ -91,7 +94,7 @@ LINTER_ARRAY=("jsonlint" "yamllint" "xmllint" "markdownlint" "shellcheck" "pylint" "perl" "raku" "rubocop" "coffeelint" "eslint" "standard" "ansible-lint" "dockerfilelint" "golangci-lint" "tflint" "stylelint" "dotenv-linter" "pwsh" "arm-ttk" "ktlint" "protolint" "clj-kondo" - "spectral" "cfn-lint" "htmlhint") + "spectral" "cfn-lint" "htmlhint" "npm-groovy-lint") ############################# # Language array for prints # @@ -100,7 +103,7 @@ LANGUAGE_ARRAY=('YML' 'JSON' 'XML' 'MARKDOWN' 'BASH' 'PERL' 'RAKU' 'PHP' 'RUBY' 'COFFEESCRIPT' 'ANSIBLE' 'JAVASCRIPT_STANDARD' 'JAVASCRIPT_ES' 'JSX' 'TSX' 'TYPESCRIPT_STANDARD' 'TYPESCRIPT_ES' 'DOCKER' 'GO' 'TERRAFORM' 'CSS' 'ENV' 'POWERSHELL' 'ARM' 'KOTLIN' 'PROTOBUF' 'CLOJURE' 'OPENAPI' - 'CFN' 'HTML') + 'CFN' 'HTML' 'GROOVY') ################### # GitHub ENV Vars # @@ -144,6 +147,7 @@ VALIDATE_EDITORCONFIG="${VALIDATE_EDITORCONFIG}" # Boolean to vali 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 VALIDATE_HTML="${VALIDATE_HTML}" # Boolean to validate language +VALIDATE_GROOVY="${VALIDATE_GROOVY}" # Boolean to validate language ############## # Debug Vars # @@ -207,6 +211,7 @@ FILE_ARRAY_KOTLIN=() # Array of files to check FILE_ARRAY_PROTOBUF=() # Array of files to check FILE_ARRAY_OPENAPI=() # Array of files to check FILE_ARRAY_HTML=() # Array of files to check +FILE_ARRAY_GROOVY=() # Array of files to check ############ # Counters # @@ -242,6 +247,7 @@ ERRORS_FOUND_KOTLIN=0 # Count of errors found ERRORS_FOUND_PROTOBUF=0 # Count of errors found ERRORS_FOUND_OPENAPI=0 # Count of errors found ERRORS_FOUND_HTML=0 # Count of errors found +ERRORS_FOUND_GROOVY=0 # Count of errors found ################################################################################ ########################## FUNCTIONS BELOW ##################################### @@ -802,6 +808,7 @@ Footer() { [ "$ERRORS_FOUND_PROTOBUF" -ne 0 ] || [ "$ERRORS_FOUND_CLOJURE" -ne 0 ] || [ "$ERRORS_FOUND_KOTLIN" -ne 0 ] || + [ "$ERRORS_FOUND_GROOVY" -ne 0 ] || [ "$ERRORS_FOUND_HTML" -ne 0 ]; then # Failed exit echo -e "${NC}${F[R]}Exiting with errors found!${NC}" @@ -861,6 +868,8 @@ GetLinterRules "JAVASCRIPT" GetLinterRules "TYPESCRIPT" # Get Golang rules GetLinterRules "GO" +# Get Groovy rules +GetLinterRules "GROOVY" # Get Docker rules GetLinterRules "DOCKER" # Get Terraform rules @@ -1054,6 +1063,17 @@ if [ "$VALIDATE_GO" == "true" ]; then LintCodebase "GO" "golangci-lint" "golangci-lint run -c $GO_LINTER_RULES" ".*\.\(go\)\$" "${FILE_ARRAY_GO[@]}" fi +################## +# GROOVY LINTING # +################## +if [ "$VALIDATE_GROOVY" == "true" ]; then + ######################### + # Lint the groovy files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" +fi + ##################### # TERRAFORM LINTING # ##################### diff --git a/lib/validation.sh b/lib/validation.sh index 8782e326..6f62c022 100755 --- a/lib/validation.sh +++ b/lib/validation.sh @@ -77,6 +77,7 @@ function GetValidationInfo() { VALIDATE_OPENAPI=$(echo "$VALIDATE_OPENAPI" | awk '{print tolower($0)}') VALIDATE_EDITORCONFIG=$(echo "$VALIDATE_EDITORCONFIG" | awk '{print tolower($0)}') VALIDATE_HTML=$(echo "$VALIDATE_HTML" | awk '{print tolower($0)}') + VALIDATE_GROOVY=$(echo "$VALIDATE_GROOVY" | awk '{print tolower($0)}') ################################################ # Determine if any linters were explicitly set # @@ -100,6 +101,7 @@ function GetValidationInfo() { $VALIDATE_TYPESCRIPT_STANDARD || -n \ $VALIDATE_DOCKER || -n \ $VALIDATE_GO || -n \ + $VALIDATE_GROOVY || -n \ $VALIDATE_TERRAFORM || -n \ $VALIDATE_POWERSHELL || -n \ $VALIDATE_ARM || -n \ @@ -551,6 +553,20 @@ function GetValidationInfo() { VALIDATE_HTML="true" fi + ###################################### + # Validate if we should check GROOVY # + ###################################### + if [[ $ANY_SET == "true" ]]; then + # Some linter flags were set - only run those set to true + if [[ -z $VALIDATE_GROOVY ]]; then + # GROOVY flag was not set - default to false + VALIDATE_GROOVY="false" + fi + else + # No linter flags were set - default all to true + VALIDATE_GROOVY="true" + fi + ####################################### # Print which linters we are enabling # ####################################### @@ -699,6 +715,11 @@ function GetValidationInfo() { else PRINT_ARRAY+=("- Excluding [HTML] files in code base...") fi + if [[ $VALIDATE_GROOVY == "true" ]]; then + PRINT_ARRAY+=("- Validating [GROOVY] files in code base...") + else + PRINT_ARRAY+=("- Excluding [GROOVY] files in code base...") + fi ############################## # Validate Ansible Directory # diff --git a/lib/worker.sh b/lib/worker.sh index eb2ed7e5..792ae2fa 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -483,6 +483,7 @@ function RunTestCases() { TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path $PROTOBUF_LINTER_RULES" ".*\.\(proto\)\$" "protobuf" TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" TestCodebase "HTML" "htmlhint" "htmlhint --config $HTML_LINTER_RULES" ".*\.\(html\)\$" "html" + TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" ################# # Footer prints # From c4647a283f395dc837fd51d17e22129237b745ce Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 14 Jul 2020 09:47:54 -0500 Subject: [PATCH 2/8] adding the templates --- .github/linters/.groovylintrc.json | 65 ++++++++++++++++++++++++++++++ TEMPLATES/.groovylintrc.json | 65 ++++++++++++++++++++++++++++++ 2 files changed, 130 insertions(+) create mode 100644 .github/linters/.groovylintrc.json create mode 100644 TEMPLATES/.groovylintrc.json diff --git a/.github/linters/.groovylintrc.json b/.github/linters/.groovylintrc.json new file mode 100644 index 00000000..474f8151 --- /dev/null +++ b/.github/linters/.groovylintrc.json @@ -0,0 +1,65 @@ +{ + "extends": "recommended", + "rules": { + "CatchException": { + "enabled": false + }, + "CatchThrowable": { + "enabled": false + }, + "ClassJavadoc": { + "enabled": false + }, + "ClosureAsLastMethodParameter": { + "enabled": false + }, + "DuplicateNumberLiteral": { + "enabled": false + }, + "DuplicateStringLiteral": { + "enabled": false + }, + "FieldTypeRequired": { + "enabled": false + }, + "JavaIoPackageAccess": { + "enabled": false + }, + "MethodParameterTypeRequired": { + "enabled": false + }, + "MethodSize": { + "enabled": false + }, + "NoDef": { + "enabled": false + }, + "PrintStackTrace": { + "enabled": false + }, + "PropertyName": { + "enabled": false + }, + "SpaceAroundMapEntryColon": { + "enabled": false + }, + "SystemExit": { + "enabled": false + }, + "UnnecessaryGetter": { + "enabled": false + }, + "UnnecessaryObjectReferences": { + "enabled": false + }, + "UnnecessarySetter": { + "enabled": false + }, + "VariableName": { + "enabled": false + }, + "VariableTypeRequired": { + "enabled": false + } + } +} diff --git a/TEMPLATES/.groovylintrc.json b/TEMPLATES/.groovylintrc.json new file mode 100644 index 00000000..474f8151 --- /dev/null +++ b/TEMPLATES/.groovylintrc.json @@ -0,0 +1,65 @@ +{ + "extends": "recommended", + "rules": { + "CatchException": { + "enabled": false + }, + "CatchThrowable": { + "enabled": false + }, + "ClassJavadoc": { + "enabled": false + }, + "ClosureAsLastMethodParameter": { + "enabled": false + }, + "DuplicateNumberLiteral": { + "enabled": false + }, + "DuplicateStringLiteral": { + "enabled": false + }, + "FieldTypeRequired": { + "enabled": false + }, + "JavaIoPackageAccess": { + "enabled": false + }, + "MethodParameterTypeRequired": { + "enabled": false + }, + "MethodSize": { + "enabled": false + }, + "NoDef": { + "enabled": false + }, + "PrintStackTrace": { + "enabled": false + }, + "PropertyName": { + "enabled": false + }, + "SpaceAroundMapEntryColon": { + "enabled": false + }, + "SystemExit": { + "enabled": false + }, + "UnnecessaryGetter": { + "enabled": false + }, + "UnnecessaryObjectReferences": { + "enabled": false + }, + "UnnecessarySetter": { + "enabled": false + }, + "VariableName": { + "enabled": false + }, + "VariableTypeRequired": { + "enabled": false + } + } +} From 995048321e148475664efdbe2b4321695ccc63cf Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Tue, 14 Jul 2020 11:48:31 -0500 Subject: [PATCH 3/8] fixed parse --- Dockerfile | 4 ++-- lib/linter.sh | 2 +- lib/worker.sh | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4088461c..1ff70db5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,7 +37,7 @@ ARG RAKUBREW_HOME=/tmp/rakubrew #################### # Run APK installs # #################### -RUN apk add --no-cache \ +RUN apk add --update --no-cache \ ansible-lint \ bash \ curl \ @@ -50,7 +50,7 @@ RUN apk add --no-cache \ make \ musl-dev \ npm \ - nodejs \ + nodejs-current \ openjdk8-jre \ perl \ php7 \ diff --git a/lib/linter.sh b/lib/linter.sh index 15424722..19715716 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1071,7 +1071,7 @@ if [ "$VALIDATE_GROOVY" == "true" ]; then # Lint the groovy files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" + LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -s" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" fi ##################### diff --git a/lib/worker.sh b/lib/worker.sh index 792ae2fa..a1744219 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -483,7 +483,7 @@ function RunTestCases() { TestCodebase "PROTOBUF" "protolint" "protolint lint --config_path $PROTOBUF_LINTER_RULES" ".*\.\(proto\)\$" "protobuf" TestCodebase "OPENAPI" "spectral" "spectral lint -r $OPENAPI_LINTER_RULES" ".*\.\(ymlopenapi\|jsonopenapi\)\$" "openapi" TestCodebase "HTML" "htmlhint" "htmlhint --config $HTML_LINTER_RULES" ".*\.\(html\)\$" "html" - TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -f" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" + TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -s" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" ################# # Footer prints # From 1c1784a8190b1973f83f223d54bbd713c2eeb67f Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Wed, 22 Jul 2020 11:48:06 -0500 Subject: [PATCH 4/8] fixed format --- docs/disabling-linters.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index 3188104b..e1963e56 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -713,7 +713,7 @@ def variable = 1; /* groovylint-disable */ ``` --------------------------------------------------------------------------------- +--- ## Dockerfile From 183a8f0ea3d4aa418df81cbd27edcdd3fb81f8e6 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Wed, 22 Jul 2020 11:59:46 -0500 Subject: [PATCH 5/8] fixed bug --- .../reports/{expected-JSON.tap => expected-JSON.tap.ignored} | 0 lib/linter.sh | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename .automation/test/json/reports/{expected-JSON.tap => expected-JSON.tap.ignored} (100%) diff --git a/.automation/test/json/reports/expected-JSON.tap b/.automation/test/json/reports/expected-JSON.tap.ignored similarity index 100% rename from .automation/test/json/reports/expected-JSON.tap rename to .automation/test/json/reports/expected-JSON.tap.ignored diff --git a/lib/linter.sh b/lib/linter.sh index 41e35bd4..14ca1b0e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -755,7 +755,7 @@ GetGitHubVars() { ############################ # Validate we have a value # ############################ - if [ -z "${GITHUB_TOKEN}" ]; then + if [ -z "${GITHUB_TOKEN}" ] && [[ ${RUN_LOCAL} == "false" ]]; then echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Failed to get [GITHUB_TOKEN]!${NC}" echo -e "${NC}${B[R]}${F[W]}ERROR:${NC}[${GITHUB_TOKEN}]${NC}" echo -e "${NC}${B[R]}${F[W]}ERROR!${NC} Please set a [GITHUB_TOKEN] from the main workflow environment to take advantage of multiple status reports!${NC}" From 4a5adc95485b9b656a9b0a2ddd5015cdcf59bb25 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Thu, 23 Jul 2020 08:22:30 -0500 Subject: [PATCH 6/8] forgot that gradle action --- lib/buildFileList.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index d06b3678..2f0df142 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -439,7 +439,7 @@ function BuildFileList() { # Set the READ_ONLY_CHANGE_FLAG since this could be exec # ########################################################## READ_ONLY_CHANGE_FLAG=1 - elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ]; then + elif [ "$FILE_TYPE" == "groovy" ] || [ "$FILE_TYPE" == "jenkinsfile" ] || [ "$FILE_TYPE" == "gradle" ]; then ################################ # Append the file to the array # ################################ From 264157912578ba8eca991b77d08ecafd4a7e4488 Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Thu, 23 Jul 2020 12:52:43 -0500 Subject: [PATCH 7/8] Adding it --- lib/linter.sh | 706 +++++++++++++++++++++++++------------------------- lib/worker.sh | 32 ++- 2 files changed, 381 insertions(+), 357 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index c9150aeb..06bb4884 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1055,42 +1055,42 @@ GetValidationInfo ######################## # Get the linter rules # ######################## -# Get YML rules -GetLinterRules "YAML" -# Get Markdown rules -GetLinterRules "MARKDOWN" -# Get Python rules -GetLinterRules "PYTHON" -# Get Ruby rules -GetLinterRules "RUBY" -# Get Coffeescript rules -GetLinterRules "COFFEESCRIPT" # Get Ansible rules GetLinterRules "ANSIBLE" -# Get JavaScript rules -GetLinterRules "JAVASCRIPT" -# Get TypeScript rules -GetLinterRules "TYPESCRIPT" +# Get ARM rules +GetLinterRules "ARM" +# Get CLOUDFORMATION rules +GetLinterRules "CLOUDFORMATION" +# Get Coffeescript rules +GetLinterRules "COFFEESCRIPT" +# Get CSS rules +GetLinterRules "CSS" +# Get DART rules +GetLinterRules "DART" +# Get Docker rules +GetLinterRules "DOCKER" # Get Golang rules GetLinterRules "GO" # Get Groovy rules GetLinterRules "GROOVY" -# Get Docker rules -GetLinterRules "DOCKER" -# Get Terraform rules -GetLinterRules "TERRAFORM" -# Get PowerShell rules -GetLinterRules "POWERSHELL" -# Get ARM rules -GetLinterRules "ARM" -# Get CSS rules -GetLinterRules "CSS" -# Get CLOUDFORMATION rules -GetLinterRules "CLOUDFORMATION" -# Get DART rules -GetLinterRules "DART" # Get HTML rules GetLinterRules "HTML" +# Get JavaScript rules +GetLinterRules "JAVASCRIPT" +# Get Markdown rules +GetLinterRules "MARKDOWN" +# Get PowerShell rules +GetLinterRules "POWERSHELL" +# Get Python rules +GetLinterRules "PYTHON" +# Get Ruby rules +GetLinterRules "RUBY" +# Get Terraform rules +GetLinterRules "TERRAFORM" +# Get TypeScript rules +GetLinterRules "TYPESCRIPT" +# Get YML rules +GetLinterRules "YAML" ################################# # Check if were in verbose mode # @@ -1129,48 +1129,48 @@ if [ "${VALIDATE_ALL_CODEBASE}" == "false" ]; then BuildFileList fi -############### -# YML LINTING # -############### -if [ "${VALIDATE_YAML}" == "true" ]; then - ###################### - # Lint the Yml Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "YML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YML[@]}" +################### +# ANSIBLE LINTING # +################### +if [ "${VALIDATE_ANSIBLE}" == "true" ]; then + ########################## + # Lint the Ansible files # + ########################## + # Due to the nature of how we want to validate Ansible, we cannot use the + # standard loop, since it looks for an ansible folder, excludes certain + # files, and looks for additional changes, it should be an outlier + LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var fi -################ -# JSON LINTING # -################ -if [ "${VALIDATE_JSON}" == "true" ]; then - ####################### - # Lint the json files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" -fi +######################## +# ARM Template LINTING # +######################## +if [ "${VALIDATE_ARM}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every json file is an ARM file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' -############### -# XML LINTING # -############### -if [ "${VALIDATE_XML}" == "true" ]; then - ###################### - # Lint the XML Files # - ###################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" -fi + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectARMFile "${FILE}"; then + FILE_ARRAY_ARM+=("${FILE}") + fi + done -#################### -# MARKDOWN LINTING # -#################### -if [ "${VALIDATE_MARKDOWN}" == "true" ]; then - ########################### - # Lint the Markdown Files # - ########################### + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + + ############################### + # Lint the ARM Template files # + ############################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" + LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" fi ################ @@ -1184,17 +1184,6 @@ if [ "${VALIDATE_BASH}" == "true" ]; then LintCodebase "BASH" "shellcheck" "shellcheck --color" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" fi -################## -# PYTHON LINTING # -################## -if [ "${VALIDATE_PYTHON}" == "true" ]; then - ######################### - # Lint the python files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON[@]}" -fi - ########################## # CLOUDFORMATION LINTING # ########################## @@ -1226,52 +1215,18 @@ if [ "${VALIDATE_CLOUDFORMATION}" == "true" ]; then LintCodebase "CLOUDFORMATION" "cfn-lint" "cfn-lint --config-file ${CLOUDFORMATION_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_CLOUDFORMATION[@]}" fi -################ -# PERL LINTING # -################ -if [ "${VALIDATE_PERL}" == "true" ]; then - ####################### - # Lint the perl files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PERL" "perl" "perl -Mstrict -cw" ".*\.\(pl\)\$" "${FILE_ARRAY_PERL[@]}" -fi - -################ -# RAKU LINTING # -################ -if [ "${VALIDATE_RAKU}" == "true" ]; then - ####################### - # Lint the raku files # - ####################### - echo "${GITHUB_WORKSPACE}/META6.json" - if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then - cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . - fi - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" -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 # -################ -if [ "${VALIDATE_RUBY}" == "true" ]; then - ####################### - # Lint the ruby files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" +################### +# CLOJURE LINTING # +################### +if [ "${VALIDATE_CLOJURE}" == "true" ]; then + ################################# + # Get Clojure standard rules # + ################################# + GetStandardRules "clj-kondo" + ######################### + # Lint the Clojure files # + ######################### + LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" fi ######################## @@ -1285,6 +1240,65 @@ if [ "${VALIDATE_COFFEE}" == "true" ]; then LintCodebase "COFFEESCRIPT" "coffeelint" "coffeelint -f ${COFFEESCRIPT_LINTER_RULES}" ".*\.\(coffee\)\$" "${FILE_ARRAY_COFFEESCRIPT[@]}" fi +############### +# CSS LINTING # +############### +if [ "${VALIDATE_CSS}" == "true" ]; then + ################################# + # Get CSS standard rules # + ################################# + GetStandardRules "stylelint" + ############################# + # Lint the CSS files # + ############################# + LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" +fi + +################ +# DART LINTING # +################ +if [ "${VALIDATE_DART}" == "true" ]; then + ####################### + # Lint the Dart files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" +fi + +################## +# DOCKER LINTING # +################## +if [ "${VALIDATE_DOCKER}" == "true" ]; then + ######################### + # Lint the docker files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file + LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" +fi + +######################## +# EDITORCONFIG LINTING # +######################## +if [ "${VALIDATE_EDITORCONFIG}" == "true" ]; then + #################################### + # Lint the files with editorconfig # + #################################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" +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[@]}" +fi + ################## # GOLANG LINTING # ################## @@ -1304,31 +1318,21 @@ if [ "$VALIDATE_GROOVY" == "true" ]; then # Lint the groovy files # ######################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -s" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" + LintCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "${FILE_ARRAY_GROOVY[@]}" fi -##################### -# TERRAFORM LINTING # -##################### -if [ "${VALIDATE_TERRAFORM}" == "true" ]; then - ############################ - # Lint the Terraform files # - ############################ - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" -fi - -################### -# ANSIBLE LINTING # -################### -if [ "${VALIDATE_ANSIBLE}" == "true" ]; then - ########################## - # Lint the Ansible files # - ########################## - # Due to the nature of how we want to validate Ansible, we cannot use the - # standard loop, since it looks for an ansible folder, excludes certain - # files, and looks for additional changes, it should be an outlier - LintAnsibleFiles "${ANSIBLE_LINTER_RULES}" # Passing rules but not needed, dont want to exclude unused var +################ +# HTML LINTING # +################ +if [ "${VALIDATE_HTML}" == "true" ]; then + ########################### + # Get HTML standard rules # + ########################### + GetStandardRules "htmlhint" + ####################### + # Lint the HTML files # + ####################### + LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" fi ###################### @@ -1357,6 +1361,17 @@ if [ "${VALIDATE_JAVASCRIPT_STANDARD}" == "true" ]; then LintCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "${FILE_ARRAY_JAVASCRIPT_STANDARD[@]}" fi +################ +# JSON LINTING # +################ +if [ "${VALIDATE_JSON}" == "true" ]; then + ####################### + # Lint the json files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "JSON" "jsonlint" "jsonlint" ".*\.\(json\)\$" "${FILE_ARRAY_JSON[@]}" +fi + ###################### # JSX LINTING # ###################### @@ -1368,6 +1383,186 @@ if [ "${VALIDATE_JSX}" == "true" ]; then LintCodebase "JSX" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(jsx\)\$" "${FILE_ARRAY_JSX[@]}" 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_KOTLIN[@]}" +fi + +#################### +# MARKDOWN LINTING # +#################### +if [ "${VALIDATE_MARKDOWN}" == "true" ]; then + ########################### + # Lint the Markdown Files # + ########################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "MARKDOWN" "markdownlint" "markdownlint -c ${MARKDOWN_LINTER_RULES}" ".*\.\(md\)\$" "${FILE_ARRAY_MARKDOWN[@]}" +fi + +################### +# OPENAPI LINTING # +################### +if [ "${VALIDATE_OPENAPI}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + 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 + FILE_ARRAY_OPENAPI+=("${FILE}") + fi + done + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + + ########################## + # Lint the OpenAPI files # + ########################## + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" +fi + +################ +# PERL LINTING # +################ +if [ "${VALIDATE_PERL}" == "true" ]; then + ####################### + # Lint the perl files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + 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 + +###################### +# POWERSHELL LINTING # +###################### +if [ "${VALIDATE_POWERSHELL}" == "true" ]; then + ############################################################### + # For POWERSHELL, ensure PSScriptAnalyzer module is available # + ############################################################### + ValidatePowershellModules + + ############################# + # Lint the powershell files # + ############################# + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" +fi + +#################### +# PROTOBUF LINTING # +#################### +if [ "${VALIDATE_PROTOBUF}" == "true" ]; then + ####################### + # Lint the Protocol Buffers files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" +fi + +################## +# PYTHON LINTING # +################## +if [ "${VALIDATE_PYTHON}" == "true" ]; then + ######################### + # Lint the python files # + ######################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "PYTHON" "pylint" "pylint --rcfile ${PYTHON_LINTER_RULES}" ".*\.\(py\)\$" "${FILE_ARRAY_PYTHON[@]}" +fi + +################ +# RAKU LINTING # +################ +if [ "${VALIDATE_RAKU}" == "true" ]; then + ####################### + # Lint the raku files # + ####################### + echo "${GITHUB_WORKSPACE}/META6.json" + if [ -e "${GITHUB_WORKSPACE}/META6.json" ]; then + cd "${GITHUB_WORKSPACE}" && zef install --deps-only --/test . + fi + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RAKU" "raku" "raku -I ${GITHUB_WORKSPACE}/lib -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "${FILE_ARRAY_RAKU[@]}" +fi + +################ +# RUBY LINTING # +################ +if [ "${VALIDATE_RUBY}" == "true" ]; then + ####################### + # Lint the ruby files # + ####################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" +fi + +###################### +# AWS STATES LINTING # +###################### +if [ "${VALIDATE_STATES}" == "true" ]; then + # If we are validating all codebase we need to build file list because not every json file is an aws states file + if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then + ############################################################################### + # Set the file seperator to newline to allow for grabbing objects with spaces # + ############################################################################### + IFS=$'\n' + + mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) + for FILE in "${LIST_FILES[@]}"; do + if DetectAWSStatesFIle "${FILE}"; then + FILE_ARRAY_STATES+=("${FILE}") + fi + done + + ########################### + # Set IFS back to default # + ########################### + IFS="${DEFAULT_IFS}" + fi + + ######################### + # Lint the STATES files # + ######################### + LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" +fi + +##################### +# TERRAFORM LINTING # +##################### +if [ "${VALIDATE_TERRAFORM}" == "true" ]; then + ############################ + # Lint the Terraform files # + ############################ + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "${FILE_ARRAY_TERRAFORM[@]}" +fi + ###################### # TSX LINTING # ###################### @@ -1403,220 +1598,25 @@ if [ "${VALIDATE_TYPESCRIPT_STANDARD}" == "true" ]; then fi ############### -# CSS LINTING # +# XML LINTING # ############### -if [ "${VALIDATE_CSS}" == "true" ]; then - ################################# - # Get CSS standard rules # - ################################# - GetStandardRules "stylelint" - ############################# - # Lint the CSS files # - ############################# - LintCodebase "CSS" "stylelint" "stylelint --config ${CSS_LINTER_RULES}" ".*\.\(css\)\$" "${FILE_ARRAY_CSS[@]}" +if [ "${VALIDATE_XML}" == "true" ]; then + ###################### + # Lint the XML Files # + ###################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "XML" "xmllint" "xmllint" ".*\.\(xml\)\$" "${FILE_ARRAY_XML[@]}" fi ############### -# ENV LINTING # +# YML LINTING # ############### -if [ "${VALIDATE_ENV}" == "true" ]; then - ####################### - # Lint the env files # - ####################### +if [ "${VALIDATE_YAML}" == "true" ]; then + ###################### + # Lint the Yml Files # + ###################### # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - 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_KOTLIN[@]}" -fi - -######################## -# EDITORCONFIG LINTING # -######################## -if [ "${VALIDATE_EDITORCONFIG}" == "true" ]; then - #################################### - # Lint the files with editorconfig # - #################################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" "^.*$" "${FILE_ARRAY_ENV[@]}" -fi - -################## -# DART LINTING # -################## -if [ "${VALIDATE_DART}" == "true" ]; then - ####################### - # Lint the Dart files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "DART" "dart" "dartanalyzer --fatal-infos --fatal-warnings --options ${DART_LINTER_RULES}" ".*\.\(dart\)\$" "${FILE_ARRAY_DART[@]}" -fi - -################## -# DOCKER LINTING # -################## -if [ "${VALIDATE_DOCKER}" == "true" ]; then - ######################### - # Lint the docker files # - ######################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - # NOTE: dockerfilelint's "-c" option expects the folder *containing* the DOCKER_LINTER_RULES file - LintCodebase "DOCKER" "dockerfilelint" "dockerfilelint -c $(dirname ${DOCKER_LINTER_RULES})" ".*\(Dockerfile\)\$" "${FILE_ARRAY_DOCKER[@]}" -fi - -################### -# CLOJURE LINTING # -################### -if [ "${VALIDATE_CLOJURE}" == "true" ]; then - ################################# - # Get Clojure standard rules # - ################################# - GetStandardRules "clj-kondo" - ######################### - # Lint the Clojure files # - ######################### - LintCodebase "CLOJURE" "clj-kondo" "clj-kondo --config ${CLOJURE_LINTER_RULES} --lint" ".*\.\(clj\|cljs\|cljc\|edn\)\$" "${FILE_ARRAY_CLOJURE[@]}" -fi - -################## -# PROTOBUF LINTING # -################## -if [ "${VALIDATE_PROTOBUF}" == "true" ]; then - ####################### - # Lint the Protocol Buffers files # - ####################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "PROTOBUF" "protolint" "protolint lint --config_path ${PROTOBUF_LINTER_RULES}" ".*\.\(proto\)\$" "${FILE_ARRAY_PROTOBUF[@]}" -fi - -###################### -# POWERSHELL LINTING # -###################### -if [ "${VALIDATE_POWERSHELL}" == "true" ]; then - ############################################################### - # For POWERSHELL, ensure PSScriptAnalyzer module is available # - ############################################################### - ValidatePowershellModules - - ############################# - # Lint the powershell files # - ############################# - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "POWERSHELL" "pwsh" "Invoke-ScriptAnalyzer -EnableExit -Settings ${POWERSHELL_LINTER_RULES} -Path" ".*\.\(ps1\|psm1\|psd1\|ps1xml\|pssc\|psrc\|cdxml\)\$" "${FILE_ARRAY_POWERSHELL[@]}" -fi - -######################## -# ARM Template LINTING # -######################## -if [ "${VALIDATE_ARM}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an ARM file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' - - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectARMFile "${FILE}"; then - FILE_ARRAY_ARM+=("${FILE}") - fi - done - - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi - - ############################### - # Lint the ARM Template files # - ############################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "ARM" "arm-ttk" "Import-Module ${ARM_TTK_PSD1} ; \${config} = \$(Import-PowerShellDataFile -Path ${ARM_LINTER_RULES}) ; Test-AzTemplate @config -TemplatePath" "disabledfileext" "${FILE_ARRAY_ARM[@]}" -fi - -################### -# OPENAPI LINTING # -################### -if [ "${VALIDATE_OPENAPI}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every yml/json file is an OpenAPI file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' - - 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 - FILE_ARRAY_OPENAPI+=("${FILE}") - fi - done - - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi - - ########################## - # Lint the OpenAPI files # - ########################## - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "OPENAPI" "spectral" "spectral lint -r ${OPENAPI_LINTER_RULES}" "disabledfileext" "${FILE_ARRAY_OPENAPI[@]}" -fi - -################ -# HTML LINTING # -################ -if [ "${VALIDATE_HTML}" == "true" ]; then - ################################# - # Get HTML standard rules # - ################################# - GetStandardRules "htmlhint" - ############################# - # Lint the HTML files # - ############################# - LintCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "${FILE_ARRAY_HTML[@]}" -fi - -###################### -# AWS STATES LINTING # -###################### -if [ "${VALIDATE_STATES}" == "true" ]; then - # If we are validating all codebase we need to build file list because not every json file is an aws states file - if [ "${VALIDATE_ALL_CODEBASE}" == "true" ]; then - ############################################################################### - # Set the file seperator to newline to allow for grabbing objects with spaces # - ############################################################################### - IFS=$'\n' - - mapfile -t LIST_FILES < <(find "${GITHUB_WORKSPACE}" -type f -regex ".*\.\(json\)\$" 2>&1) - for FILE in "${LIST_FILES[@]}"; do - if DetectAWSStatesFIle "${FILE}"; then - FILE_ARRAY_STATES+=("${FILE}") - fi - done - - ########################### - # Set IFS back to default # - ########################### - IFS="${DEFAULT_IFS}" - fi - - ######################### - # Lint the STATES files # - ######################### - LintCodebase "STATES" "asl-validator" "asl-validator --json-path" "disabledfileext" "${FILE_ARRAY_STATES[@]}" + LintCodebase "YML" "yamllint" "yamllint -c ${YAML_LINTER_RULES}" ".*\.\(yml\|yaml\)\$" "${FILE_ARRAY_YML[@]}" fi ########### diff --git a/lib/worker.sh b/lib/worker.sh index f6bb3808..607c3fd6 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -138,10 +138,11 @@ function LintCodebase() { # Lint the files # ################## for FILE in "${LIST_FILES[@]}"; do - ##################### - # Get the file name # - ##################### + ################################### + # Get the file name and directory # + ################################### FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) ##################################################### # Make sure we dont lint node modules or test cases # @@ -193,6 +194,17 @@ function LintCodebase() { pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" exit $? 2>&1 ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then + ####################################### + # Lint the file with the updated path # + ####################################### + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) else ################################ # Lint the file with the rules # @@ -326,6 +338,7 @@ function TestCodebase() { # Get the file name # ##################### FILE_NAME=$(basename "${FILE}" 2>&1) + DIR_NAME=$(dirname "${FILE}" 2>&1) ############################ # Get the file pass status # @@ -400,6 +413,17 @@ function TestCodebase() { pwsh -NoProfile -NoLogo -Command "${LINTER_COMMAND} ${FILE}; if (\${Error}.Count) { exit 1 }" exit $? 2>&1 ) + ############################################################################### + # Corner case for groovy as we have to pass it as path and file in ant format # + ############################################################################### + elif [[ ${FILE_TYPE} == "GROOVY" ]]; then + ####################################### + # Lint the file with the updated path # + ####################################### + LINT_CMD=$( + cd "${GITHUB_WORKSPACE}" || exit + ${LINTER_COMMAND} --path "${DIR_NAME}" --files "$FILE_NAME" 2>&1 + ) else ################################ # Lint the file with the rules # @@ -566,7 +590,7 @@ function RunTestCases() { TestCodebase "EDITORCONFIG" "editorconfig-checker" "editorconfig-checker" ".*\.ext$" "editorconfig-checker" TestCodebase "ENV" "dotenv-linter" "dotenv-linter" ".*\.\(env\)\$" "env" TestCodebase "GO" "golangci-lint" "golangci-lint run -c ${GO_LINTER_RULES}" ".*\.\(go\)\$" "golang" - TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES -s" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" + TestCodebase "GROOVY" "npm-groovy-lint" "npm-groovy-lint -c $GROOVY_LINTER_RULES --failon error" ".*\.\(groovy\|jenkinsfile\|gradle\)\$" "groovy" TestCodebase "HTML" "htmlhint" "htmlhint --config ${HTML_LINTER_RULES}" ".*\.\(html\)\$" "html" TestCodebase "JAVASCRIPT_ES" "eslint" "eslint --no-eslintrc -c ${JAVASCRIPT_LINTER_RULES}" ".*\.\(js\)\$" "javascript" TestCodebase "JAVASCRIPT_STANDARD" "standard" "standard ${JAVASCRIPT_STANDARD_LINTER_RULES}" ".*\.\(js\)\$" "javascript" From d2bb1dd6c1c0f32bb792cd6c13a6a0c776cae2af Mon Sep 17 00:00:00 2001 From: Lucas Gravley <29484535+admiralAwkbar@users.noreply.github.com> Date: Thu, 23 Jul 2020 13:01:04 -0500 Subject: [PATCH 8/8] Fix spacing --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 25612c63..aa163769 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **EDITORCONFIG** | [editorconfig-checker](https://github.com/editorconfig-checker/editorconfig-checker) | | **ENV** | [dotenv-linter](https://github.com/dotenv-linter/dotenv-linter) | | **Golang** | [golangci-lint](https://github.com/golangci/golangci-lint) | -| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | +| **Groovy** | [npm-groovy-lint](https://github.com/nvuillam/npm-groovy-lint) | | **HTMLHint** | [HTMLHint](https://github.com/htmlhint/HTMLHint) | | **JavaScript** | [eslint](https://eslint.org/) [standard js](https://standardjs.com/) | | **JSON** | [jsonlint](https://github.com/zaach/jsonlint) |