@@ -55,12 +55,9 @@ cd "${KUBE_ROOT}"
55
55
failure_file=" ${KUBE_ROOT} /hack/.staticcheck_failures"
56
56
kube::util::check-file-in-alphabetical-order " ${failure_file} "
57
57
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.
62
58
all_packages=()
63
59
while IFS=' ' read -r line; do
60
+ # Prepend './' to get staticcheck to treat these as paths, not packages.
64
61
all_packages+=(" ./$line " )
65
62
done < <( hack/make-rules/helpers/cache_go_dirs.sh " ${KUBE_ROOT} /_tmp/all_go_dirs" |
66
63
grep " ^${FOCUS:- .} " |
@@ -71,7 +68,6 @@ failing_packages=()
71
68
if [[ -z $FOCUS ]]; then # Ignore failing_packages in FOCUS mode
72
69
while IFS=' ' read -r line; do failing_packages+=(" $line " ); done < <( cat " $failure_file " )
73
70
fi
74
- unset IFS
75
71
errors=()
76
72
not_failing=()
77
73
@@ -93,8 +89,8 @@ while read -r error; do
93
89
fi
94
90
done < <( staticcheck -checks " ${checks} " " ${all_packages[@]} " 2> /dev/null || true)
95
91
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[*]}" )
98
94
unset IFS
99
95
for pkg in " ${failing_packages[@]} " ; do
100
96
if ! kube::util::array_contains " $pkg " " ${really_failing[@]} " ; then
112
108
113
109
# Check to be sure all the packages that should pass check are.
114
110
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 .'
116
112
else
117
113
{
118
114
echo " Errors from staticcheck:"
121
117
done
122
118
echo
123
119
echo ' Please review the above warnings. You can test via:'
124
- echo " staticcheck -checks \" ${checks} \" "
120
+ echo ' hack/verify- staticcheck.sh <failing package> '
125
121
echo ' If the above warnings do not make sense, you can exempt the line or file. See:'
126
122
echo ' https://staticcheck.io/docs/#ignoring-problems'
127
123
echo
0 commit comments