From 0d849cd5e0024062937d8dd34269cf07dbb85d03 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Fri, 28 Aug 2020 20:42:32 +0200 Subject: [PATCH 01/10] Lint shell files with shfmt --- .automation/test/shfmt/.editorconfig | 3 +++ .automation/test/shfmt/README.md | 19 +++++++++++++++++++ .automation/test/shfmt/shell_bad_1.sh | 17 +++++++++++++++++ .automation/test/shfmt/shell_good_1.sh | 17 +++++++++++++++++ Dockerfile | 13 +++++++++++++ README.md | 3 ++- docs/disabling-linters.md | 5 +++++ lib/linter.sh | 18 ++++++++++++++++-- lib/worker.sh | 1 + 9 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 .automation/test/shfmt/.editorconfig create mode 100644 .automation/test/shfmt/README.md create mode 100644 .automation/test/shfmt/shell_bad_1.sh create mode 100644 .automation/test/shfmt/shell_good_1.sh diff --git a/.automation/test/shfmt/.editorconfig b/.automation/test/shfmt/.editorconfig new file mode 100644 index 00000000..f41c803b --- /dev/null +++ b/.automation/test/shfmt/.editorconfig @@ -0,0 +1,3 @@ +[*.ext] +indent_style = space +indent_size = 4 diff --git a/.automation/test/shfmt/README.md b/.automation/test/shfmt/README.md new file mode 100644 index 00000000..19c6d867 --- /dev/null +++ b/.automation/test/shfmt/README.md @@ -0,0 +1,19 @@ +# SHFMT Test Cases + +This folder holds the test cases for **SHFMT**. + +## 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/shfmt/shell_bad_1.sh b/.automation/test/shfmt/shell_bad_1.sh new file mode 100644 index 00000000..ee5435e5 --- /dev/null +++ b/.automation/test/shfmt/shell_bad_1.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# CMD +HELLO_WORLD=$(echo "Hello World" | cut -f1 -d' ' 2>&1) + +# Load the error code +ERROR_CODE=$? + +# Check the shell +if [ ${ERROR_CODE} -ne 0 ]; then + echo "We did it!" + exit 0 +else + echo "We done goofed it..." + echo "${HELLO_WORLD}" + exit 1 +fi diff --git a/.automation/test/shfmt/shell_good_1.sh b/.automation/test/shfmt/shell_good_1.sh new file mode 100644 index 00000000..0121b042 --- /dev/null +++ b/.automation/test/shfmt/shell_good_1.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +# CMD +HELLO_WORLD=$(echo "Hello World" | cut -f1 -d' ' 2>&1) + +# Load the error code +ERROR_CODE=$? + +# Check the shell +if [ ${ERROR_CODE} -ne 0 ]; then + echo "We did it!" + exit 0 +else + echo "We done goofed it..." + echo "${HELLO_WORLD}" + exit 1 +fi diff --git a/Dockerfile b/Dockerfile index 6dee160a..5714b242 100644 --- a/Dockerfile +++ b/Dockerfile @@ -281,6 +281,18 @@ RUN R -e "install.packages(list.dirs('/home/r-library',recursive = FALSE), repos COPY --from=chktex /usr/bin/chktex /usr/bin/ RUN cd ~ && touch .chktexrc +################# +# Install shfmt # +################# +ENV GO111MODULE=on + +ENV GOROOT=/usr/lib/go +ENV GOPATH=/go +ENV PATH="$PATH":"$GOROOT"/bin +ENV PATH="$PATH":"$GOPATH"/bin +RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin +RUN go get mvdan.cc/sh/v3/cmd/shfmt + ########################################### # Load GitHub Env Vars for GitHub Actions # ########################################### @@ -345,6 +357,7 @@ ENV ACTIONS_RUNNER_DEBUG=${ACTIONS_RUNNER_DEBUG} \ VALIDATE_R=${VALIDATE_R} \ VALIDATE_RAKU=${VALIDATE_RAKU} \ VALIDATE_RUBY=${VALIDATE_RUBY} \ + VALIDATE_SHELL_SHFMT=${VALIDATE_SHELL_SHFMT} \ VALIDATE_STATES=${VALIDATE_STATES} \ VALIDATE_SQL=${VALIDATE_SQL} \ VALIDATE_TERRAFORM=${VALIDATE_TERRAFORM} \ diff --git a/README.md b/README.md index 6a4a9bba..22085a4f 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,7 @@ Developers on **GitHub** can call the **GitHub Action** to lint their code base | **R** | [lintr](https://github.com/jimhester/lintr) | | **Raku** | [Raku](https://raku.org) | | **Ruby** | [RuboCop](https://github.com/rubocop-hq/rubocop) | -| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [Bash-exec] | +| **Shell** | [Shellcheck](https://github.com/koalaman/shellcheck) / [Bash-exec] / [shfmt](https://github.com/mvdan/sh) | | **SQL** | [sql-lint](https://github.com/joereynolds/sql-lint) | | **Terraform** | [tflint](https://github.com/terraform-linters/tflint) / [terrascan](https://github.com/accurics/terrascan) | | **TypeScript** | [eslint](https://eslint.org/) / [standard js](https://standardjs.com/) | @@ -236,6 +236,7 @@ But if you wish to select or exclude specific linters, we give you full control | **VALIDATE_R** | `true` | Flag to enable or disable the linting process of the R language. | | **VALIDATE_RAKU** | `true` | Flag to enable or disable the linting process of the Raku language. | | **VALIDATE_RUBY** | `true` | Flag to enable or disable the linting process of the Ruby language. | +| **VALIDATE_SHELL_SHFMT** | `true` | Flag to enable or disable the linting process of Shell scripts. (Utilizing: shfmt) | | **VALIDATE_STATES** | `true` | Flag to enable or disable the linting process for AWS States Language. | | **VALIDATE_SQL** | `true` | Flag to enable or disable the linting process of the SQL language. | | **VALIDATE_TERRAFORM** | `true` | Flag to enable or disable the linting process of the Terraform language. | diff --git a/docs/disabling-linters.md b/docs/disabling-linters.md index a5432d0c..7a8d949b 100644 --- a/docs/disabling-linters.md +++ b/docs/disabling-linters.md @@ -1079,6 +1079,7 @@ AllCops: ## Shell - [Shellcheck](https://github.com/koalaman/shellcheck) +- [shfmt](https://github.com/mvdan/sh) ### Shellcheck Config file @@ -1110,6 +1111,10 @@ echo "stuff" moreThings() ``` +### shfmt Config file + +shfmt [supports EditorConfig files for configuration](https://github.com/mvdan/sh#shfmt), if available. + --- ## SQL diff --git a/lib/linter.sh b/lib/linter.sh index f27b3da7..fa66e265 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -136,7 +136,7 @@ YAML_LINTER_RULES="${DEFAULT_RULES_LOCATION}/${YAML_FILE_NAME}" # Path to the ya LINTER_ARRAY=('ansible-lint' 'arm-ttk' 'asl-validator' 'bash-exec' 'black' 'cfn-lint' 'checkstyle' 'chktex' 'clj-kondo' 'coffeelint' 'dotnet-format' 'dart' 'dockerfilelint' 'dotenv-linter' 'editorconfig-checker' 'eslint' 'flake8' 'golangci-lint' 'hadolint' 'htmlhint' 'jsonlint' 'ktlint' 'lintr' 'lua' 'markdownlint' 'npm-groovy-lint' 'perl' 'protolint' - 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'spectral' 'standard' 'stylelint' 'sql-lint' + 'pwsh' 'pylint' 'raku' 'rubocop' 'shellcheck' 'shfmt' 'spectral' 'standard' 'stylelint' 'sql-lint' 'terrascan' 'tflint' 'xmllint' 'yamllint') ############################# @@ -146,7 +146,7 @@ LANGUAGE_ARRAY=('ANSIBLE' 'ARM' 'BASH' 'BASH_EXEC' 'CLOUDFORMATION' 'CLOJURE' 'C 'DART' 'DOCKERFILE' 'DOCKERFILE_HADOLINT' 'EDITORCONFIG' 'ENV' 'GO' 'GROOVY' 'HTML' 'JAVA' 'JAVASCRIPT_ES' 'JAVASCRIPT_STANDARD' 'JSON' 'JSX' 'KOTLIN' 'LATEX' 'LUA' 'MARKDOWN' 'OPENAPI' 'PERL' 'PHP_BUILTIN' 'PHP_PHPCS' 'PHP_PHPSTAN' 'PHP_PSALM' 'POWERSHELL' - 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'R' 'RAKU' 'RUBY' 'STATES' 'SQL' 'TERRAFORM' + 'PROTOBUF' 'PYTHON_BLACK' 'PYTHON_PYLINT' 'PYTHON_FLAKE8' 'R' 'RAKU' 'RUBY' 'SHELL_SHFMT' 'STATES' 'SQL' 'TERRAFORM' 'TERRAFORM_TERRASCAN' 'TSX' 'TYPESCRIPT_ES' 'TYPESCRIPT_STANDARD' 'XML' 'YAML') ############################################ @@ -211,6 +211,7 @@ VALIDATE_R="${VALIDATE_R}" # Boolean t VALIDATE_RAKU="${VALIDATE_RAKU}" # Boolean to validate language VALIDATE_RUBY="${VALIDATE_RUBY}" # Boolean to validate language VALIDATE_STATES="${VALIDATE_STATES}" # Boolean to validate language +VALIDATE_SHELL_SHFMT="${VALIDATE_SHELL_SHFMT}" # Boolean to check Shell files against editorconfig VALIDATE_SQL="${VALIDATE_SQL}" # Boolean to validate language VALIDATE_TERRAFORM="${VALIDATE_TERRAFORM}" # Boolean to validate language VALIDATE_TERRAFORM_TERRASCAN="${VALIDATE_TERRAFORM_TERRASCAN}" # Boolean to validate language @@ -404,6 +405,8 @@ ERRORS_FOUND_RAKU=0 # Count of errors found export ERRORS_FOUND_RAKU # Workaround SC2034 ERRORS_FOUND_RUBY=0 # Count of errors found export ERRORS_FOUND_RUBY # Workaround SC2034 +ERRORS_FOUND_SHELL_SHFMT=0 # Count of errors found +export ERRORS_FOUND_SHELL_SHFMT ERRORS_FOUND_STATES=0 # Count of errors found export ERRORS_FOUND_STATES # Workaround SC2034 ERRORS_FOUND_SQL=0 # Count of errors found @@ -1836,6 +1839,17 @@ if [ "${VALIDATE_RUBY}" == "true" ]; then LintCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES} --force-exclusion" ".*\.\(rb\)\$" "${FILE_ARRAY_RUBY[@]}" fi +################# +# SHFMT LINTING # +################# +if [ "${VALIDATE_SHELL_SHFMT}" == "true" ]; then + #################################### + # Lint the files with shfmt # + #################################### + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "SHELL_SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" +fi + ###################### # AWS STATES LINTING # ###################### diff --git a/lib/worker.sh b/lib/worker.sh index 352e279c..e8d8ae44 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -679,6 +679,7 @@ function RunTestCases() { TestCodebase "R" "lintr" "lintr::lint()" ".*\.\(r\|rmd\)\$" "r" TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" + TestCodebase "SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" TestCodebase "SQL" "sql-lint" "sql-lint --config ${SQL_LINTER_RULES}" ".*\.\(sql\)\$" "sql" TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" From b3a980e06f9e527c5bbda1e2b2331b6da0222d0d Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Sat, 29 Aug 2020 21:40:08 +0200 Subject: [PATCH 02/10] Fix bash-exec and terrascan versions --- lib/linter.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/linter.sh b/lib/linter.sh index fa66e265..cb20fe0f 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -467,7 +467,7 @@ GetLinterVersions() { if [[ ${LINTER} == "arm-ttk" ]]; then # Need specific command for ARM mapfile -t GET_VERSION_CMD < <(grep -iE 'version' "${ARM_TTK_PSD1}" | xargs 2>&1) - elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]]; then + elif [[ ${LINTER} == "protolint" ]] || [[ ${LINTER} == "editorconfig-checker" ]] || [[ ${LINTER} == "bash-exec" ]]; then # Need specific command for Protolint and editorconfig-checker mapfile -t GET_VERSION_CMD < <(echo "--version not supported") elif [[ ${LINTER} == "lintr" ]]; then @@ -478,6 +478,8 @@ GetLinterVersions() { elif [[ ${LINTER} == "lua" ]]; then # Semi standardversion command mapfile -t GET_VERSION_CMD < <("${LINTER}" -v 2>&1) + elif [[ ${LINTER} == "terrascan" ]]; then + mapfile -t GET_VERSION_CMD < <("${LINTER}" version 2>&1) else # Standard version command mapfile -t GET_VERSION_CMD < <("${LINTER}" --version 2>&1) From 644e69131b3799ad4ff1ab38d62473ea1a0a640e Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Sat, 29 Aug 2020 21:50:26 +0200 Subject: [PATCH 03/10] Fix shfmt test --- .automation/test/{shfmt => shell_shfmt}/.editorconfig | 3 +++ .automation/test/{shfmt => shell_shfmt}/README.md | 0 .../{shfmt/shell_bad_1.sh => shell_shfmt/shell_shfmt_bad_1.sh} | 0 .../shell_good_1.sh => shell_shfmt/shell_shfmt_good_1.sh} | 0 lib/worker.sh | 2 +- 5 files changed, 4 insertions(+), 1 deletion(-) rename .automation/test/{shfmt => shell_shfmt}/.editorconfig (51%) rename .automation/test/{shfmt => shell_shfmt}/README.md (100%) rename .automation/test/{shfmt/shell_bad_1.sh => shell_shfmt/shell_shfmt_bad_1.sh} (100%) rename .automation/test/{shfmt/shell_good_1.sh => shell_shfmt/shell_shfmt_good_1.sh} (100%) diff --git a/.automation/test/shfmt/.editorconfig b/.automation/test/shell_shfmt/.editorconfig similarity index 51% rename from .automation/test/shfmt/.editorconfig rename to .automation/test/shell_shfmt/.editorconfig index f41c803b..8c250236 100644 --- a/.automation/test/shfmt/.editorconfig +++ b/.automation/test/shell_shfmt/.editorconfig @@ -1,3 +1,6 @@ +# top-most EditorConfig file +root = true + [*.ext] indent_style = space indent_size = 4 diff --git a/.automation/test/shfmt/README.md b/.automation/test/shell_shfmt/README.md similarity index 100% rename from .automation/test/shfmt/README.md rename to .automation/test/shell_shfmt/README.md diff --git a/.automation/test/shfmt/shell_bad_1.sh b/.automation/test/shell_shfmt/shell_shfmt_bad_1.sh similarity index 100% rename from .automation/test/shfmt/shell_bad_1.sh rename to .automation/test/shell_shfmt/shell_shfmt_bad_1.sh diff --git a/.automation/test/shfmt/shell_good_1.sh b/.automation/test/shell_shfmt/shell_shfmt_good_1.sh similarity index 100% rename from .automation/test/shfmt/shell_good_1.sh rename to .automation/test/shell_shfmt/shell_shfmt_good_1.sh diff --git a/lib/worker.sh b/lib/worker.sh index e8d8ae44..d381c7d1 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -679,7 +679,7 @@ function RunTestCases() { TestCodebase "R" "lintr" "lintr::lint()" ".*\.\(r\|rmd\)\$" "r" TestCodebase "RAKU" "raku" "raku -c" ".*\.\(raku\|rakumod\|rakutest\|pm6\|pl6\|p6\)\$" "raku" TestCodebase "RUBY" "rubocop" "rubocop -c ${RUBY_LINTER_RULES}" ".*\.\(rb\)\$" "ruby" - TestCodebase "SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell" + TestCodebase "SHELL_SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "shell_shfmt" TestCodebase "STATES" "asl-validator" "asl-validator --json-path" ".*\.\(json\)\$" "states" TestCodebase "SQL" "sql-lint" "sql-lint --config ${SQL_LINTER_RULES}" ".*\.\(sql\)\$" "sql" TestCodebase "TERRAFORM" "tflint" "tflint -c ${TERRAFORM_LINTER_RULES}" ".*\.\(tf\)\$" "terraform" From f90c3a289b34a0c8324de7aedb3a6a798eaaa2ec Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Sun, 30 Aug 2020 20:18:15 +0200 Subject: [PATCH 04/10] Check if report output folder exists before listing --- lib/linter.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index cb20fe0f..b724327e 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1070,9 +1070,13 @@ Reports() { ############################################# # Print info on reports that were generated # ############################################# - info "Contents of report folder:" - OUTPUT_CONTENTS_CMD=$(ls "${REPORT_OUTPUT_FOLDER}") - info "$OUTPUT_CONTENTS_CMD" + if [ -d "${REPORT_OUTPUT_FOLDER}" ]; then + info "Contents of report folder:" + OUTPUT_CONTENTS_CMD=$(ls "${REPORT_OUTPUT_FOLDER}") + info "$OUTPUT_CONTENTS_CMD" + else + warn "Report output folder (${REPORT_OUTPUT_FOLDER}) does NOT exist." + fi fi ################################ From 59154d8dfff89a8f4baab8610d0b3040f06eb07c Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 17:04:51 +0200 Subject: [PATCH 05/10] Less layers to set Go env --- Dockerfile | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 5714b242..505d8159 100644 --- a/Dockerfile +++ b/Dockerfile @@ -286,10 +286,11 @@ RUN cd ~ && touch .chktexrc ################# ENV GO111MODULE=on -ENV GOROOT=/usr/lib/go -ENV GOPATH=/go -ENV PATH="$PATH":"$GOROOT"/bin -ENV PATH="$PATH":"$GOPATH"/bin +ENV GOROOT=/usr/lib/go \ + GOPATH=/go \ + PATH="$PATH":"$GOROOT"/bin \ + PATH="$PATH":"$GOPATH"/bin + RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin RUN go get mvdan.cc/sh/v3/cmd/shfmt From 61fcd7f44f33fa7e9adfdc6344d27857b6347801 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 18:07:01 +0200 Subject: [PATCH 06/10] Fix adding Go bins to PATH --- Dockerfile | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 505d8159..d10d260b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -284,12 +284,11 @@ RUN cd ~ && touch .chktexrc ################# # Install shfmt # ################# -ENV GO111MODULE=on +ENV GO111MODULE=on \ + GOROOT=/usr/lib/go \ + GOPATH=/go -ENV GOROOT=/usr/lib/go \ - GOPATH=/go \ - PATH="$PATH":"$GOROOT"/bin \ - PATH="$PATH":"$GOPATH"/bin +ENV PATH="$PATH":"$GOROOT"/bin:"$GOPATH"/bin RUN mkdir -p ${GOPATH}/src ${GOPATH}/bin RUN go get mvdan.cc/sh/v3/cmd/shfmt From f5331bdcd31717f3775d2e6ca00766822a727447 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 19:30:50 +0200 Subject: [PATCH 07/10] Skip shfmt if no .editorconfig file is present --- lib/linter.sh | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/linter.sh b/lib/linter.sh index b724327e..93bcc695 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -1852,8 +1852,17 @@ if [ "${VALIDATE_SHELL_SHFMT}" == "true" ]; then #################################### # Lint the files with shfmt # #################################### - # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" - LintCodebase "SHELL_SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" + EDITORCONFIG_FILE_PATH="${GITHUB_WORKSPACE}"/.editorconfig + if [ -e "$EDITORCONFIG_FILE_PATH" ]; then + # LintCodebase "FILE_TYPE" "LINTER_NAME" "LINTER_CMD" "FILE_TYPES_REGEX" "FILE_ARRAY" + LintCodebase "SHELL_SHFMT" "shfmt" "shfmt -d" ".*\.\(sh\|bash\|dash\|ksh\)\$" "${FILE_ARRAY_BASH[@]}" + else + ############################### + # No .editorconfig file found # + ############################### + warn "No .editorconfig found at:[$EDITORCONFIG_FILE_PATH]" + debug "skipping shfmt" + fi fi ###################### From 833dcb8bd8dc8c2e82a51f55c4d35e586740a16f Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 19:31:22 +0200 Subject: [PATCH 08/10] Don't check zsh files with shfmt --- lib/worker.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/worker.sh b/lib/worker.sh index d381c7d1..941d315f 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -168,6 +168,11 @@ function LintCodebase() { warn "Found [zsh] script" info "ShellCheck does NOT currently support zsh, skipping file" continue + elif [[ ${FILE_TYPE} == "SHELL_SHFMT" ]] && CheckZsh "${FILE}"; then + # ZSH file and we need to skip + warn "Found [zsh] script" + info "shfmt does NOT currently support zsh, skipping file" + continue fi ################################## From 798311822a90609e30566c30965bec9de54d878e Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 19:47:05 +0200 Subject: [PATCH 09/10] Add file path to ZSH warning messages --- lib/buildFileList.sh | 2 +- lib/worker.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 53894376..431b3d26 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -100,7 +100,7 @@ function BuildFileList() { [ "${FILE_TYPE}" == "dash" ] || [ "${FILE_TYPE}" == "ksh" ]; then # Need to check if its a zsh file as we cannot parse it if CheckZsh "${FILE}"; then - warn "Found [zsh] script" + warn "Found [zsh] script: ${FILE}" info "ShellCheck does NOT currently support zsh, skipping file" else ################################ diff --git a/lib/worker.sh b/lib/worker.sh index 941d315f..48a06745 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -165,12 +165,12 @@ function LintCodebase() { continue elif [[ ${FILE_TYPE} == "BASH" ]] && CheckZsh "${FILE}"; then # ZSH file and we need to skip - warn "Found [zsh] script" + warn "Found [zsh] script: ${FILE}" info "ShellCheck does NOT currently support zsh, skipping file" continue elif [[ ${FILE_TYPE} == "SHELL_SHFMT" ]] && CheckZsh "${FILE}"; then # ZSH file and we need to skip - warn "Found [zsh] script" + warn "Found [zsh] script: ${FILE}" info "shfmt does NOT currently support zsh, skipping file" continue fi From 228a86e5c07a8a683cabb0308602c4a0709171f2 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 31 Aug 2020 19:56:49 +0200 Subject: [PATCH 10/10] Remove duplicate output lines when checking for ZSH scripts --- lib/buildFileList.sh | 8 +++----- lib/worker.sh | 6 ++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/buildFileList.sh b/lib/buildFileList.sh index 431b3d26..bbb31e8c 100755 --- a/lib/buildFileList.sh +++ b/lib/buildFileList.sh @@ -100,8 +100,7 @@ function BuildFileList() { [ "${FILE_TYPE}" == "dash" ] || [ "${FILE_TYPE}" == "ksh" ]; then # Need to check if its a zsh file as we cannot parse it if CheckZsh "${FILE}"; then - warn "Found [zsh] script: ${FILE}" - info "ShellCheck does NOT currently support zsh, skipping file" + warn "ShellCheck and shfmt do NOT currently support zsh, skipping file" else ################################ # Append the file to the array # @@ -679,7 +678,7 @@ function CheckFileType() { ###################### # It is a ZSH script # ###################### - warn "Found [zsh] script" + warn "Found [zsh] script: ${FILE}" info "ShellCheck does NOT currently support zsh, skipping file" else ############################ @@ -712,8 +711,7 @@ function CheckZsh() { ###################### # It is a ZSH script # ###################### - warn "Found [zsh] script" - info "ShellCheck does NOT currently support zsh, skipping file" + debug "Found [zsh] script: ${FILE}" ################################################### # We found zsh file and need to return with a hit # ################################################### diff --git a/lib/worker.sh b/lib/worker.sh index 48a06745..25614675 100755 --- a/lib/worker.sh +++ b/lib/worker.sh @@ -165,13 +165,11 @@ function LintCodebase() { continue elif [[ ${FILE_TYPE} == "BASH" ]] && CheckZsh "${FILE}"; then # ZSH file and we need to skip - warn "Found [zsh] script: ${FILE}" - info "ShellCheck does NOT currently support zsh, skipping file" + warn "$LINTER_NAME does NOT currently support zsh, skipping file" continue elif [[ ${FILE_TYPE} == "SHELL_SHFMT" ]] && CheckZsh "${FILE}"; then # ZSH file and we need to skip - warn "Found [zsh] script: ${FILE}" - info "shfmt does NOT currently support zsh, skipping file" + warn "$LINTER_NAME does NOT currently support zsh, skipping file" continue fi