fix(golangci-lint): skip config verification when -c none is used

Prevents failure when no config file is specified by only
verifying config when golangci_config is non-empty.
This commit is contained in:
yongruilin
2025-07-24 21:41:28 +00:00
parent 8d28109a2b
commit d4a83b9a52

View File

@@ -140,20 +140,22 @@ if [ "${golangci_config}" ]; then
GOTOOLCHAIN="$(kube::golang::hack_tools_gotoolchain)" go -C "${KUBE_ROOT}/hack/tools/golangci-lint" build -o "${GOBIN}/sorted.so" -buildmode=plugin k8s.io/kubernetes/hack/tools/golangci-lint/sorted/plugin
fi
# Verify that the given config is valid. "golangci-lint run" does not
# Verify that the given config is valid (if one is provided). "golangci-lint run" does not
# do that, which makes it easy to miss mistakes while editing the configuration.
if ! failures=$( "${GOBIN}/golangci-lint" config verify --config="${golangci_config:-}" 2>&1 ); then
cat >&2 <<EOF
if [ "${golangci_config}" ]; then
if ! failures=$( "${GOBIN}/golangci-lint" config verify --config="${golangci_config}" 2>&1 ); then
cat >&2 <<EOF
Verification of the golangci-lint configuration failed. Command:
${GOBIN}/golangci-lint config verify --config="${golangci_config:-}")
${GOBIN}/golangci-lint config verify --config="${golangci_config}")
Result:
$failures
EOF
exit 1
exit 1
fi
fi
if [ "${golangci_config}" ]; then