Skip to content

Commit e1a5637

Browse files
committed
staticcheck follow-up to address late feedback
1 parent 46d65d0 commit e1a5637

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

hack/verify-staticcheck.sh

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,9 @@ cd "${KUBE_ROOT}"
5555
failure_file="${KUBE_ROOT}/hack/.staticcheck_failures"
5656
kube::util::check-file-in-alphabetical-order "${failure_file}"
5757

58-
export IFS=$'\n'
59-
# NOTE: when "go list -e ./..." is run within GOPATH, it turns the k8s.io/kubernetes
60-
# as the prefix, however if we run it outside it returns the full path of the file
61-
# with a leading underscore. We'll need to support both scenarios for all_packages.
6258
all_packages=()
6359
while IFS='' read -r line; do
60+
# Prepend './' to get staticcheck to treat these as paths, not packages.
6461
all_packages+=("./$line")
6562
done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" |
6663
grep "^${FOCUS:-.}" |
@@ -71,7 +68,6 @@ failing_packages=()
7168
if [[ -z $FOCUS ]]; then # Ignore failing_packages in FOCUS mode
7269
while IFS='' read -r line; do failing_packages+=("$line"); done < <(cat "$failure_file")
7370
fi
74-
unset IFS
7571
errors=()
7672
not_failing=()
7773

@@ -93,8 +89,8 @@ while read -r error; do
9389
fi
9490
done < <(staticcheck -checks "${checks}" "${all_packages[@]}" 2>/dev/null || true)
9591

96-
export IFS=$'\n'
97-
mapfile -t really_failing < <(sort -u <<<"${really_failing[*]}")
92+
export IFS=$'\n' # Expand ${really_failing[*]} to separate lines
93+
kube::util::read-array really_failing < <(sort -u <<<"${really_failing[*]}")
9894
unset IFS
9995
for pkg in "${failing_packages[@]}"; do
10096
if ! kube::util::array_contains "$pkg" "${really_failing[@]}"; then
@@ -112,7 +108,7 @@ done
112108

113109
# Check to be sure all the packages that should pass check are.
114110
if [ ${#errors[@]} -eq 0 ]; then
115-
echo 'Congratulations! All Go source files have been checked.'
111+
echo 'Congratulations! All Go source files have passed staticcheck.'
116112
else
117113
{
118114
echo "Errors from staticcheck:"
@@ -121,7 +117,7 @@ else
121117
done
122118
echo
123119
echo 'Please review the above warnings. You can test via:'
124-
echo " staticcheck -checks \"${checks}\""
120+
echo ' hack/verify-staticcheck.sh <failing package>'
125121
echo 'If the above warnings do not make sense, you can exempt the line or file. See:'
126122
echo ' https://staticcheck.io/docs/#ignoring-problems'
127123
echo

0 commit comments

Comments
 (0)