Skip to content
Browse files
hack: integrate logcheck into golangci-lint
Running logcheck as part of golangci-lint has several advantages:
- faster checking because finding files and parsing is shared
  with other linters
- gets rid of the complex and buggy
  hack/ (#106746)
- support for // nolint:logcheck
- works with Go 1.18
  • Loading branch information
pohly committed Mar 24, 2022
1 parent edffc70 commit 17e3c555c5115f8c9176bae10ba45baa04d23a7b
Showing 8 changed files with 45 additions and 118 deletions.
@@ -21,10 +21,17 @@ linters:
# - structcheck
# - varcheck
- ineffassign
- logcheck
- staticcheck
- unused

linters-settings: # please keep this alphabetized
# Installed there by hack/
path: _output/local/bin/
description: structured logging checker
go: "1.17"
checks: [

This file was deleted.

@@ -0,0 +1,22 @@
# This file contains regular expressions that are matched against <pkg>/<file>,
# for example
# By default, structured logging call parameters are checked, but usage of
# those calls is not required. That is changed on a per-file basis.
# Remember to clean the golangci-lint cache when changing the configuration and
# running the script multiple times, otherwise
# golangci-lint will report stale results:
# _output/local/bin/golangci-lint cache clean

# At this point we don't enforce the usage structured logging calls except in
# those packages that were migrated. This disables the check for other files.
-structured .*

# Now enable it again for migrated packages.
@@ -35,7 +35,6 @@ EXCLUDED_PATTERNS=(
"" # runs in separate Jenkins job once per day due to high network usage
"verify-*" # Don't run any scripts that intended to be run dockerized
"" # Do not run levee analysis by default while KEP-1933 implementation is in alpha.
"" # TODO(dims) Need to get this running with golang 1.18

# Exclude generated-files-remake in certain cases, if they're running in a separate job.
@@ -11,6 +11,6 @@ require ( v0.1.5 v1.6.4 v0.2.2 v0.0.0-20210917071902-331d2323a192 v0.0.0-20220321210246-c697110cd8ac v0.2.0
@@ -1521,8 +1521,8 @@ v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9 v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k= v0.2.2 h1:MNh1AVMyVX23VUHE2O27jm6lNj3vjO5DexS4A1xvnzk= v0.2.2/go.mod h1:lPVVZ2BS5TfnjLyizF7o7hv7j9/L+8cZY2hLyjP9cGY= v0.0.0-20210917071902-331d2323a192 h1:u27Xm1of9MTDM1CZW3hg0Vv04ohywEG152G8mpr9n8Y= v0.0.0-20210917071902-331d2323a192/go.mod h1:DXW3Mv8xqJvjXWiBSBHrK2O4mq5LMD0clqkv3b1g9HA= v0.0.0-20220321210246-c697110cd8ac h1:c2NQfDLtcwrPdD9pnUcRPlMJ719zgRzdlufHULIW7mU= v0.0.0-20220321210246-c697110cd8ac/go.mod h1:DXW3Mv8xqJvjXWiBSBHrK2O4mq5LMD0clqkv3b1g9HA= v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE= v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA= v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
@@ -36,14 +36,25 @@ PATH="${GOBIN}:${PATH}"
export GO111MODULE=on

# Install golangci-lint
echo 'installing golangci-lint '
echo "installing golangci-lint and logcheck plugin from hack/tools into ${GOBIN}"
pushd "${KUBE_ROOT}/hack/tools" >/dev/null
go install
go build -o "${GOBIN}/" -buildmode=plugin
popd >/dev/null

cd "${KUBE_ROOT}"

# The config is in ${KUBE_ROOT}/.golangci.yaml
# 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
# (
# 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
if [[ "$#" -gt 0 ]]; then

This file was deleted.

0 comments on commit 17e3c55

Please sign in to comment.