Fix bug in golint script when no files

The script would get a 1 return code from grep when there are no files
in a directory, after filtering generated filenames.  This would cause
the script to exit unexpectedly.
This commit is contained in:
Tim Hockin 2021-01-22 16:14:37 -08:00
parent 105e8f8467
commit 1b07b0d648

View File

@ -69,7 +69,13 @@ for p in "${all_packages[@]}"; do
# completely.
# Ref: https://github.com/kubernetes/kubernetes/pull/67675
# Ref: https://github.com/golang/lint/issues/68
failedLint=$(find "$p"/*.go | grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" | xargs -L1 golint 2>/dev/null)
files=$(find "$p"/*.go \
| grep -vE "(zz_generated.*.go|generated.pb.go|generated.proto|types_swagger_doc_generated.go)" || true)
if [ -z "${files}" ]; then
continue
fi
failedLint=$(echo "${files}" | xargs -L1 golint 2>/dev/null)
kube::util::array_contains "$p" "${failing_packages[@]}" && in_failing=$? || in_failing=$?
if [[ -n "${failedLint}" ]] && [[ "${in_failing}" -ne "0" ]]; then
errors+=( "${failedLint}" )