From 2d513e13305ea7038649ad7cb43a426a1a787589 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 28 Feb 2023 13:30:30 +0100 Subject: [PATCH 1/3] golangci-lint: show more information about actual invocation Both env variables and parameters are relevant for users who want to invoke the command directly or follow how it is used. --- hack/verify-golangci-lint.sh | 42 +++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index 3d661233781..d143a89ed1f 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -26,12 +26,25 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" source "${KUBE_ROOT}/hack/lib/util.sh" -kube::golang::verify_go_version - # Ensure that we find the binaries we build before anything else. export GOBIN="${KUBE_OUTPUT_BINPATH}" PATH="${GOBIN}:${PATH}" +invocation=(./hack/verify-golangci-lint.sh "$@") + +# The logcheck plugin currently has to be configured via env variables +# (https://github.com/golangci/golangci-lint/issues/1512). +# +# Remember to clean the golangci-lint cache when changing +# the configuration and running this script multiple times, +# otherwise golangci-lint will report stale results: +# _output/local/bin/golangci-lint cache clean +golangci=(env LOGCHECK_CONFIG="${KUBE_ROOT}/hack/logcheck.conf" "${GOBIN}/golangci-lint" run) +golangci_config="${KUBE_ROOT}/.golangci.yaml" +golangci+=(--config="${golangci_config}") + +kube::golang::verify_go_version + # Explicitly opt into go modules, even though we're inside a GOPATH directory export GO111MODULE=on @@ -44,29 +57,18 @@ popd >/dev/null cd "${KUBE_ROOT}" -## The config is in ${KUBE_ROOT}/.golangci.yaml where it will be found -## even when golangci-lint is invoked in a sub-directory. -## -## The logcheck plugin currently has to be configured via env variables -## (https://github.com/golangci/golangci-lint/issues/1512). -## -## Remember to clean the golangci-lint cache when changing -## the configuration and running this script multiple times, -## otherwise golangci-lint will report stale results: -## _output/local/bin/golangci-lint cache clean -export LOGCHECK_CONFIG="${KUBE_ROOT}/hack/logcheck.conf" - -echo 'running golangci-lint ' >&2 res=0 if [[ "$#" -gt 0 ]]; then - golangci-lint run "$@" >&2 || res=$? + echo "running ${golangci[*]} $*" >&2 + "${golangci[@]}" "$@" >&2 || res=$? else - golangci-lint run ./... >&2 || res=$? + echo "running ${golangci[*]} ./..." >&2 + "${golangci[@]}" ./... >&2 || res=$? for d in staging/src/k8s.io/*; do MODPATH="staging/src/k8s.io/$(basename "${d}")" - echo "running golangci-lint for ${KUBE_ROOT}/${MODPATH}" + echo "running ( cd ${KUBE_ROOT}/${MODPATH}; ${golangci[*]} --path-prefix ${MODPATH} ./... )" pushd "${KUBE_ROOT}/${MODPATH}" >/dev/null - golangci-lint --path-prefix "${MODPATH}" run ./... >&2 || res=$? + "${golangci[@]}" --path-prefix "${MODPATH}" ./... >&2 || res=$? popd >/dev/null done fi @@ -77,7 +79,7 @@ if [ "$res" -eq 0 ]; then else { echo - echo 'Please review the above warnings. You can test via "./hack/verify-golangci-lint.sh"' + echo "Please review the above warnings. You can test via \"${invocation[*]}\"" echo 'If the above warnings do not make sense, you can exempt this warning with a comment' echo ' (if your reviewer is okay with it).' echo 'In general please prefer to fix the error, we have already disabled specific lints' From cf2e6291d1564a2885ebee37d8253856723342fc Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 3 May 2022 13:22:47 +0200 Subject: [PATCH 2/3] hack: move golangci-lint config files Because the script now explicitly selects the configuration file, the files no longer have to be in the root directory. Having them in hack without the leading dot is better because they then have the same owners as the script and are more visible. The downside is that manual invocations of golangci-lint without the parameter no longer work. --- .golangci.yaml => hack/golangci.yaml | 2 +- hack/verify-golangci-lint.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename .golangci.yaml => hack/golangci.yaml (97%) diff --git a/.golangci.yaml b/hack/golangci.yaml similarity index 97% rename from .golangci.yaml rename to hack/golangci.yaml index 29de7f79162..c79fd1cd1ed 100644 --- a/.golangci.yaml +++ b/hack/golangci.yaml @@ -32,7 +32,7 @@ linters-settings: # please keep this alphabetized custom: logcheck: # Installed there by hack/verify-golangci-lint.sh. - path: _output/local/bin/logcheck.so + path: ../_output/local/bin/logcheck.so description: structured logging checker original-url: k8s.io/klog/hack/tools gocritic: diff --git a/hack/verify-golangci-lint.sh b/hack/verify-golangci-lint.sh index d143a89ed1f..11ab9ec53d7 100755 --- a/hack/verify-golangci-lint.sh +++ b/hack/verify-golangci-lint.sh @@ -40,7 +40,7 @@ invocation=(./hack/verify-golangci-lint.sh "$@") # otherwise golangci-lint will report stale results: # _output/local/bin/golangci-lint cache clean golangci=(env LOGCHECK_CONFIG="${KUBE_ROOT}/hack/logcheck.conf" "${GOBIN}/golangci-lint" run) -golangci_config="${KUBE_ROOT}/.golangci.yaml" +golangci_config="${KUBE_ROOT}/hack/golangci.yaml" golangci+=(--config="${golangci_config}") kube::golang::verify_go_version From fa98647a3078b3c33d9ad5bd53d62af4b9ef2971 Mon Sep 17 00:00:00 2001 From: Patrick Ohly Date: Tue, 2 Aug 2022 08:21:53 +0200 Subject: [PATCH 3/3] golangci-lint: update logcheck original-url --- hack/golangci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hack/golangci.yaml b/hack/golangci.yaml index c79fd1cd1ed..b3ecc488721 100644 --- a/hack/golangci.yaml +++ b/hack/golangci.yaml @@ -34,7 +34,7 @@ linters-settings: # please keep this alphabetized # Installed there by hack/verify-golangci-lint.sh. path: ../_output/local/bin/logcheck.so description: structured logging checker - original-url: k8s.io/klog/hack/tools + original-url: k8s.io/logtools/logcheck gocritic: enabled-checks: - equalFold