From eded42747b4512364eb30228b610b9c648aa0082 Mon Sep 17 00:00:00 2001 From: Marco Ferrari Date: Mon, 5 Feb 2024 11:49:22 +0100 Subject: [PATCH] fix: don't add unnecessary empty lines (#5221) --- Dockerfile | 2 +- lib/functions/buildFileList.sh | 8 ++++---- lib/functions/worker.sh | 10 +++++----- lib/linter.sh | 10 +++++----- test/inspec/super-linter/controls/super_linter.rb | 3 ++- 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4814f9e4..e6d3b8fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -379,7 +379,7 @@ ENV PATH="${PATH}:${DART_SDK}/bin:/root/.pub-cache/bin" # Initialize Terrascan # Initialize ChkTeX config file -RUN terrascan init \ +RUN terrascan init --log-level "debug" \ && touch ~/.chktexrc ENTRYPOINT ["/action/lib/linter.sh"] diff --git a/lib/functions/buildFileList.sh b/lib/functions/buildFileList.sh index ed160261..b1312791 100755 --- a/lib/functions/buildFileList.sh +++ b/lib/functions/buildFileList.sh @@ -150,14 +150,14 @@ function BuildFileList() { local RESULTS_OBJECT RESULTS_OBJECT= - if ! RESULTS_OBJECT=$(jq -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then + if ! RESULTS_OBJECT=$(jq --raw-output -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then fatal "Error loading results when building the file list: ${RESULTS_OBJECT}" fi debug "RESULTS_OBJECT for ${FILE_TYPE}:\n${RESULTS_OBJECT}" local STDOUT_BUILD_FILE_LIST # Get raw output so we can strip quotes from the data we load - if ! STDOUT_BUILD_FILE_LIST="$(jq --raw-output '.[].Stdout' <<<"${RESULTS_OBJECT}")"; then + if ! STDOUT_BUILD_FILE_LIST="$(jq --raw-output '.[].Stdout[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stdout when building the file list: ${STDOUT_BUILD_FILE_LIST}" fi @@ -168,12 +168,12 @@ function BuildFileList() { fi local STDERR_BUILD_FILE_LIST - if ! STDERR_BUILD_FILE_LIST="$(jq --raw-output '.[].Stderr' <<<"${RESULTS_OBJECT}")"; then + if ! STDERR_BUILD_FILE_LIST="$(jq --raw-output '.[].Stderr[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stderr when building the file list:\n${STDERR_BUILD_FILE_LIST}" fi if [ -n "${STDERR_BUILD_FILE_LIST}" ]; then - info "Command output when building the file list:\n------\n${STDERR_BUILD_FILE_LIST}\n------" + info "Stderr when building the file list:\n------\n${STDERR_BUILD_FILE_LIST}\n------" else debug "Stderr when building the file list is empty" fi diff --git a/lib/functions/worker.sh b/lib/functions/worker.sh index 16b95bf0..66c5a126 100755 --- a/lib/functions/worker.sh +++ b/lib/functions/worker.sh @@ -173,7 +173,7 @@ function LintCodebase() { local RESULTS_OBJECT RESULTS_OBJECT= - if ! RESULTS_OBJECT=$(jq -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then + if ! RESULTS_OBJECT=$(jq --raw-output -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then fatal "Error loading results for ${FILE_TYPE}: ${RESULTS_OBJECT}" fi debug "RESULTS_OBJECT for ${FILE_TYPE}:\n${RESULTS_OBJECT}" @@ -187,8 +187,8 @@ function LintCodebase() { debug "Set INDEX for ${FILE_TYPE} to: ${INDEX}" local STDOUT_LINTER - # Get raw output so we can strip quotes from the data we load - if ! STDOUT_LINTER="$(jq --raw-output '.[].Stdout' <<<"${RESULTS_OBJECT}")"; then + # Get raw output so we can strip quotes from the data we load. Also, strip the final newline to avoid adding it two times + if ! STDOUT_LINTER="$(jq --raw-output '.[].Stdout[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stdout for ${FILE_TYPE}:\n${STDOUT_LINTER}" fi @@ -199,12 +199,12 @@ function LintCodebase() { fi local STDERR_LINTER - if ! STDERR_LINTER="$(jq --raw-output '.[].Stderr' <<<"${RESULTS_OBJECT}")"; then + if ! STDERR_LINTER="$(jq --raw-output '.[].Stderr[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stderr for ${FILE_TYPE}:\n${STDERR_LINTER}" fi if [ -n "${STDERR_LINTER}" ]; then - info "Command output for ${FILE_TYPE}:\n------\n${STDERR_LINTER}\n------" + info "Stderr contents for ${FILE_TYPE}:\n------\n${STDERR_LINTER}\n------" else debug "Stderr for ${FILE_TYPE} is empty" fi diff --git a/lib/linter.sh b/lib/linter.sh index f57e1f23..f44cd26c 100755 --- a/lib/linter.sh +++ b/lib/linter.sh @@ -929,13 +929,13 @@ debug "PARALLEL_COMMAND_OUTPUT when running linters (exit code: ${PARALLEL_COMMA debug "Parallel output file (${PARALLEL_RESULTS_FILE_PATH}) contents when running linters:\n$(cat "${PARALLEL_RESULTS_FILE_PATH}")" RESULTS_OBJECT= -if ! RESULTS_OBJECT=$(jq -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then +if ! RESULTS_OBJECT=$(jq --raw-output -n '[inputs]' "${PARALLEL_RESULTS_FILE_PATH}"); then fatal "Error loading results when building the file list: ${RESULTS_OBJECT}" fi debug "RESULTS_OBJECT when running linters:\n${RESULTS_OBJECT}" -# Get raw output so we can strip quotes from the data we load -if ! STDOUT_LINTERS="$(jq --raw-output '.[].Stdout' <<<"${RESULTS_OBJECT}")"; then +# Get raw output so we can strip quotes from the data we load. Also, strip the final newline to avoid adding it two times +if ! STDOUT_LINTERS="$(jq --raw-output '.[].Stdout[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stdout when running linters:\n${STDOUT_LINTERS}" fi @@ -945,12 +945,12 @@ else debug "Stdout when running linters is empty" fi -if ! STDERR_LINTERS="$(jq --raw-output '.[].Stderr' <<<"${RESULTS_OBJECT}")"; then +if ! STDERR_LINTERS="$(jq --raw-output '.[].Stderr[:-1]' <<<"${RESULTS_OBJECT}")"; then fatal "Error when loading stderr for ${FILE_TYPE}:\n${STDERR_LINTERS}" fi if [ -n "${STDERR_LINTERS}" ]; then - info "Command output for ${FILE_TYPE}:\n------\n${STDERR_LINTERS}\n------" + info "Stderr when running linters:\n------\n${STDERR_LINTERS}\n------" else debug "Stderr when running linters is empty" fi diff --git a/test/inspec/super-linter/controls/super_linter.rb b/test/inspec/super-linter/controls/super_linter.rb index 402120ff..dc844a00 100644 --- a/test/inspec/super-linter/controls/super_linter.rb +++ b/test/inspec/super-linter/controls/super_linter.rb @@ -483,7 +483,8 @@ control "super-linter-validate-files" do "/action/lib/.automation/.yaml-lint.yml", "/action/lib/.automation/phpcs.xml", "/action/lib/.automation/phpstan.neon", - "/action/lib/.automation/psalm.xml" + "/action/lib/.automation/psalm.xml", + "/root/.chktexrc" ] files.each do |item|