Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix shellcheck failures on and verify-test-featuregates.sh #76890

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion hack/.shellcheck_failures
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
./hack/verify-codegen.sh
./hack/verify-golint.sh
./hack/verify-no-vendor-cycles.sh
./hack/verify-test-featuregates.sh
./test/cmd/apply.sh
./test/cmd/apps.sh
./test/cmd/authorization.sh
Expand Down
2 changes: 1 addition & 1 deletion hack/verify-openapi-spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ _tmp="${KUBE_ROOT}/_tmp"

mkdir -p "${_tmp}"
cp -a "${SPECROOT}" "${TMP_SPECROOT}"
trap 'cp -a "${TMP_SPECROOT}" "${SPECROOT}"/..; rm -rf "${_tmp}"' EXIT SIGINT
trap 'cp -a ${TMP_SPECROOT} ${SPECROOT}/..; rm -rf ${_tmp}' EXIT SIGINT
rm "${SPECROOT}"/*
cp "${TMP_SPECROOT}/BUILD" "${SPECROOT}/BUILD"
cp "${TMP_SPECROOT}/README.md" "${SPECROOT}/README.md"
Expand Down
6 changes: 3 additions & 3 deletions hack/verify-test-featuregates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/init.sh"

cd "${KUBE_ROOT}"

rc=0

# find test files accessing the mutable global feature gate or interface
direct_sets=$(grep -n --include *_test.go -R 'MutableFeatureGate' . 2>/dev/null) || true
direct_sets=$(grep -n --include './*_test.go' -R 'MutableFeatureGate' . 2>/dev/null) || true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref: 
In ./hack/verify-test-featuregates.sh line 29:
direct_sets=$(grep -n --include *_test.go -R 'MutableFeatureGate' . 2>/dev/null) || true
                                ^-------^ SC2062: Quote the grep pattern so the shell won't interpret it.
                                ^-------^ SC2063: Grep uses regex, but this looks like a glob.
                                ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options.
  https://www.shellcheck.net/wiki/SC2062 -- Quote the grep pattern so the she...
  https://www.shellcheck.net/wiki/SC2063 -- Grep uses regex, but this looks l...
  https://www.shellcheck.net/wiki/SC2128 -- Expanding an array without an ind...

if [[ -n "${direct_sets}" ]]; then
echo "Test files may not access mutable global feature gates directly:" >&2
echo "${direct_sets}" >&2
Expand All @@ -38,7 +38,7 @@ if [[ -n "${direct_sets}" ]]; then
fi

# find test files calling SetFeatureGateDuringTest and not calling the result
missing_defers=$(grep -n --include *_test.go -R 'SetFeatureGateDuringTest' . 2>/dev/null | egrep -v "defer .*\\)\\(\\)$") || true
missing_defers=$(grep -n --include './*_test.go' -R 'SetFeatureGateDuringTest' . 2>/dev/null | grep -E -v "defer .*\\)\\(\\)$") || true
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ref:
In ./hack/verify-test-featuregates.sh line 41:
missing_defers=$(grep -n --include *_test.go -R 'SetFeatureGateDuringTest' . 2>/dev/null | egrep -v "defer .*\\)\\(\\)$") || true
                                   ^-------^ SC2062: Quote the grep pattern so the shell won't interpret it.
                                   ^-------^ SC2063: Grep uses regex, but this looks like a glob.
                                   ^-- SC2035: Use ./*glob* or -- *glob* so names with dashes won't become options.
                                                                                           ^---^ SC2196: egrep is non-standard and deprecated. Use grep -E instead.

if [[ -n "${missing_defers}" ]]; then
echo "Invalid invocations of utilfeaturetesting.SetFeatureGateDuringTest():" >&2
echo "${missing_defers}" >&2
Expand Down