k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/golangci-hints.yaml (about) 1 # golangci-lint is used in Kubernetes with different configurations that 2 # enable an increasing amount of checks: 3 # - golangci.yaml is the most permissive configuration. All existing code 4 # passed. 5 # - golangci-strict.yaml adds checks that all new code in pull requests 6 # must pass. 7 # - golangci-hints.yaml adds checks for code patterns where developer 8 # and reviewer may decide whether findings should get addressed before 9 # merging. Beware that the golangci-lint output includes also the 10 # issues that must be fixed and doesn't indicate how severe each issue 11 # is (https://gophers.slack.com/archives/CS0TBRKPC/p1685721815275349). 12 # 13 # All three flavors are generated from golangci.yaml.in with 14 # hack/update-golangci-lint-config.sh. 15 16 run: 17 timeout: 30m 18 skip-files: 19 - "^zz_generated.*" 20 21 output: 22 sort-results: true 23 24 issues: 25 max-issues-per-linter: 0 26 max-same-issues: 0 27 28 # The default excludes disable the "should have comment or be unexported" check from revive. 29 # We want that to be enabled, therefore we have to disable all default excludes and 30 # add those back one-by-one that we want. See https://github.com/golangci/golangci-lint/issues/456#issuecomment-617470264 31 exclude-use-default: false 32 exclude: 33 # staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore 34 - ineffective break statement. Did you mean to break out of the outer loop 35 36 # Excluding configuration per-path, per-linter, per-text and per-source 37 exclude-rules: 38 # exclude ineffassign linter for generated files for conversion 39 - path: conversion\.go 40 linters: 41 - ineffassign 42 43 # SSA Extract calls are allowed in tests. 44 - linters: 45 - forbidigo 46 text: should not be used because managedFields was removed 47 path: _test.go$ 48 49 # The Kubernetes naming convention for conversion functions uses underscores 50 # and intentionally deviates from normal Go conventions to make those function 51 # names more readable. Same for SetDefaults_*. 52 # 53 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627 54 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592 55 - linters: 56 - stylecheck 57 - revive 58 text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)" 59 60 # This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91). 61 - linters: 62 - ginkgolinter 63 text: use a function call in (Eventually|Consistently) 64 65 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435 66 - linters: 67 - gocritic 68 text: "ifElseChain: rewrite if-else to switch statement" 69 70 # Only packages listed here opt into the strict "exported symbols must be documented". 71 # 72 # Exclude texts from https://github.com/golangci/golangci-lint/blob/ab3c3cd69e602ff53bb4c3e2c188f0caeb80305d/pkg/config/issues.go#L11-L103 73 - linters: 74 - golint 75 - revive 76 - stylecheck 77 text: comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|comment on exported (method|function|type|const)|should have( a package)? comment|comment should be of the form|exported (.+) should have comment( \(or a comment on this block\))? or be unexported|package comment should be of the form "(.+)...|comment on exported (.+) should be of the form "(.+)...|should have a package comment 78 path-except: cmd/kubeadm 79 80 linters: 81 disable-all: false 82 enable: # please keep this alphabetized 83 - forbidigo 84 - ginkgolinter 85 - gocritic 86 - govet 87 - errorlint 88 - ineffassign 89 - logcheck 90 - revive 91 - staticcheck 92 - stylecheck 93 - unused 94 95 linters-settings: # please keep this alphabetized 96 custom: 97 logcheck: 98 # Installed there by hack/verify-golangci-lint.sh. 99 path: ../_output/local/bin/logcheck.so 100 description: structured logging checker 101 original-url: k8s.io/logtools/logcheck 102 settings: 103 config: | 104 # hack/logcheck.conf contains regular expressions that are matched against <pkg>/<file>, 105 # for example k8s.io/cmd/kube-scheduler/app/config/config.go. 106 # 107 # By default, structured logging call parameters are checked, but usage of 108 # those calls is not required. That is changed on a per-file basis. 109 # 110 # Remember to clean the golangci-lint cache when changing the configuration and 111 # running the verify-golangci-lint.sh script multiple times, otherwise 112 # golangci-lint will report stale results: 113 # _output/local/bin/golangci-lint cache clean 114 115 # At this point we don't enforce the usage structured logging calls except in 116 # those packages that were migrated. This disables the check for other files. 117 -structured .* 118 119 # Now enable it again for migrated packages. 120 structured k8s.io/kubernetes/cmd/kubelet/.* 121 structured k8s.io/kubernetes/pkg/kubelet/.* 122 structured k8s.io/kubernetes/pkg/proxy/.* 123 structured k8s.io/kms/.* 124 structured k8s.io/apiserver/pkg/storage/value/.* 125 structured k8s.io/apiserver/pkg/server/options/encryptionconfig/.* 126 127 # The following packages have been migrated to contextual logging. 128 # Packages matched here do not have to be listed above because 129 # "contextual" implies "structured". 130 contextual k8s.io/api/.* 131 contextual k8s.io/apimachinery/pkg/util/runtime/.* 132 contextual k8s.io/client-go/metadata/.* 133 contextual k8s.io/client-go/tools/events/.* 134 contextual k8s.io/client-go/tools/record/.* 135 contextual k8s.io/component-helpers/.* 136 contextual k8s.io/cri-api/.* 137 contextual k8s.io/cri-client/.* 138 contextual k8s.io/dynamic-resource-allocation/.* 139 contextual k8s.io/endpointslice/.* 140 contextual k8s.io/kms/.* 141 contextual k8s.io/kube-controller-manager/.* 142 contextual k8s.io/kube-proxy/.* 143 contextual k8s.io/kube-scheduler/.* 144 contextual k8s.io/sample-apiserver/.* 145 contextual k8s.io/sample-cli-plugin/.* 146 contextual k8s.io/sample-controller/.* 147 contextual k8s.io/kubernetes/cmd/kube-proxy/.* 148 contextual k8s.io/kubernetes/cmd/kube-scheduler/.* 149 contextual k8s.io/kubernetes/pkg/controller/.* 150 contextual k8s.io/kubernetes/pkg/scheduler/.* 151 contextual k8s.io/kubernetes/test/e2e/dra/.* 152 153 # As long as contextual logging is alpha or beta, all WithName, WithValues, 154 # NewContext calls have to go through klog. Once it is GA, we can lift 155 # this restriction. Whether we then do a global search/replace remains 156 # to be decided. 157 with-helpers .* 158 forbidigo: 159 analyze-types: true 160 forbid: 161 - p: ^managedfields\.ExtractInto$ 162 pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$ 163 msg: should not be used because managedFields was removed 164 - p: \.Extract 165 pkg: ^k8s\.io/client-go/applyconfigurations/ 166 msg: should not be used because managedFields was removed 167 - p: ^gomega\.BeTrue$ 168 pkg: ^github.com/onsi/gomega$ 169 msg: "it does not produce a good failure message - use BeTrueBecause with an explicit printf-style failure message instead, or plain Go: if ... { ginkgo.Fail(...) }" 170 - p: ^gomega\.BeFalse$ 171 pkg: ^github.com/onsi/gomega$ 172 msg: "it does not produce a good failure message - use BeFalseBecause with an explicit printf-style failure message instead, or plain Go: if ... { ginkgo.Fail(...) }" 173 revive: 174 # Only these rules are enabled. 175 rules: 176 - name: exported 177 arguments: 178 - disableStutteringCheck 179 staticcheck: 180 checks: 181 - "all"