mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 05:57:25 +00:00
staticcheck follow-up to address late feedback
This commit is contained in:
parent
46d65d0a46
commit
e1a5637c41
@ -55,12 +55,9 @@ cd "${KUBE_ROOT}"
|
|||||||
failure_file="${KUBE_ROOT}/hack/.staticcheck_failures"
|
failure_file="${KUBE_ROOT}/hack/.staticcheck_failures"
|
||||||
kube::util::check-file-in-alphabetical-order "${failure_file}"
|
kube::util::check-file-in-alphabetical-order "${failure_file}"
|
||||||
|
|
||||||
export IFS=$'\n'
|
|
||||||
# NOTE: when "go list -e ./..." is run within GOPATH, it turns the k8s.io/kubernetes
|
|
||||||
# as the prefix, however if we run it outside it returns the full path of the file
|
|
||||||
# with a leading underscore. We'll need to support both scenarios for all_packages.
|
|
||||||
all_packages=()
|
all_packages=()
|
||||||
while IFS='' read -r line; do
|
while IFS='' read -r line; do
|
||||||
|
# Prepend './' to get staticcheck to treat these as paths, not packages.
|
||||||
all_packages+=("./$line")
|
all_packages+=("./$line")
|
||||||
done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" |
|
done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" |
|
||||||
grep "^${FOCUS:-.}" |
|
grep "^${FOCUS:-.}" |
|
||||||
@ -71,7 +68,6 @@ failing_packages=()
|
|||||||
if [[ -z $FOCUS ]]; then # Ignore failing_packages in FOCUS mode
|
if [[ -z $FOCUS ]]; then # Ignore failing_packages in FOCUS mode
|
||||||
while IFS='' read -r line; do failing_packages+=("$line"); done < <(cat "$failure_file")
|
while IFS='' read -r line; do failing_packages+=("$line"); done < <(cat "$failure_file")
|
||||||
fi
|
fi
|
||||||
unset IFS
|
|
||||||
errors=()
|
errors=()
|
||||||
not_failing=()
|
not_failing=()
|
||||||
|
|
||||||
@ -93,8 +89,8 @@ while read -r error; do
|
|||||||
fi
|
fi
|
||||||
done < <(staticcheck -checks "${checks}" "${all_packages[@]}" 2>/dev/null || true)
|
done < <(staticcheck -checks "${checks}" "${all_packages[@]}" 2>/dev/null || true)
|
||||||
|
|
||||||
export IFS=$'\n'
|
export IFS=$'\n' # Expand ${really_failing[*]} to separate lines
|
||||||
mapfile -t really_failing < <(sort -u <<<"${really_failing[*]}")
|
kube::util::read-array really_failing < <(sort -u <<<"${really_failing[*]}")
|
||||||
unset IFS
|
unset IFS
|
||||||
for pkg in "${failing_packages[@]}"; do
|
for pkg in "${failing_packages[@]}"; do
|
||||||
if ! kube::util::array_contains "$pkg" "${really_failing[@]}"; then
|
if ! kube::util::array_contains "$pkg" "${really_failing[@]}"; then
|
||||||
@ -112,7 +108,7 @@ done
|
|||||||
|
|
||||||
# Check to be sure all the packages that should pass check are.
|
# Check to be sure all the packages that should pass check are.
|
||||||
if [ ${#errors[@]} -eq 0 ]; then
|
if [ ${#errors[@]} -eq 0 ]; then
|
||||||
echo 'Congratulations! All Go source files have been checked.'
|
echo 'Congratulations! All Go source files have passed staticcheck.'
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
echo "Errors from staticcheck:"
|
echo "Errors from staticcheck:"
|
||||||
@ -121,7 +117,7 @@ else
|
|||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
echo 'Please review the above warnings. You can test via:'
|
echo 'Please review the above warnings. You can test via:'
|
||||||
echo " staticcheck -checks \"${checks}\""
|
echo ' hack/verify-staticcheck.sh <failing package>'
|
||||||
echo 'If the above warnings do not make sense, you can exempt the line or file. See:'
|
echo 'If the above warnings do not make sense, you can exempt the line or file. See:'
|
||||||
echo ' https://staticcheck.io/docs/#ignoring-problems'
|
echo ' https://staticcheck.io/docs/#ignoring-problems'
|
||||||
echo
|
echo
|
||||||
|
Loading…
Reference in New Issue
Block a user