k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/golangci.yaml.in (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 {{- if .Base}} 50 51 # TODO(oscr) Remove these excluded directories and fix findings. Due to large amount of findings in different components 52 # with different owners it's hard to fix everything in a single pr. This will therefore be done in multiple prs. 53 - path: (pkg/volume/*|test/*|azure/*|pkg/cmd/wait*|request/bearertoken/*|metrics/*|filters/*) 54 linters: 55 - gocritic 56 {{- end}} 57 58 # The Kubernetes naming convention for conversion functions uses underscores 59 # and intentionally deviates from normal Go conventions to make those function 60 # names more readable. Same for SetDefaults_*. 61 # 62 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627 63 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592 64 - linters: 65 - stylecheck 66 - revive 67 text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)" 68 69 # This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91). 70 - linters: 71 - ginkgolinter 72 text: use a function call in (Eventually|Consistently) 73 74 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435 75 - linters: 76 - gocritic 77 text: "ifElseChain: rewrite if-else to switch statement" 78 79 # Only packages listed here opt into the strict "exported symbols must be documented". 80 # 81 # Exclude texts from https://github.com/golangci/golangci-lint/blob/ab3c3cd69e602ff53bb4c3e2c188f0caeb80305d/pkg/config/issues.go#L11-L103 82 - linters: 83 - golint 84 - revive 85 - stylecheck 86 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 87 path-except: cmd/kubeadm 88 89 {{- if not .Hints}} 90 91 # The following issues were deemed "might be worth fixing, needs to be 92 # decided on a case-by-case basis". This was initially decided by a 93 # majority of the developers who voted in 94 # https://github.com/kubernetes/kubernetes/issues/117288 and may evolve 95 # over time. 96 97 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008918 98 - linters: 99 - gocritic 100 text: "assignOp:" 101 102 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507016854 103 - linters: 104 - gosimple 105 text: "S1002: should omit comparison to bool constant" 106 107 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507023980 108 - linters: 109 - gosimple 110 text: "S1016: should convert opts .* instead of using struct literal" 111 112 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507026758 113 - linters: 114 - gosimple 115 text: "S1033: unnecessary guard around call to delete" 116 117 # Didn't make it into https://github.com/kubernetes/kubernetes/issues/117288. 118 # Discussion on Slack concluded that "it's hard to have a universal policy for all 119 # functions marked deprecated" and thus this can only be a hint which must 120 # be considered on a case-by-case basis. 121 - linters: 122 - staticcheck 123 text: "SA1019: .*is deprecated" 124 125 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507030071 126 - linters: 127 - stylecheck 128 text: "ST1012: error var .* should have name of the form ErrFoo" 129 130 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507031224 131 - linters: 132 - stylecheck 133 text: "ST1023: should omit type .* from declaration; it will be inferred from the right-hand side" 134 {{- end}} 135 136 linters: 137 disable-all: {{if .Base -}} true {{- else -}} false {{- end}} 138 enable: # please keep this alphabetized 139 - forbidigo 140 - ginkgolinter 141 - gocritic 142 - govet 143 {{- if .Hints}} 144 - errorlint 145 {{- end}} 146 - ineffassign 147 - logcheck 148 - revive 149 - staticcheck 150 - stylecheck 151 - unused 152 {{- if .Strict}} 153 disable: 154 # https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507008359 155 - errcheck 156 {{- end}} 157 158 linters-settings: # please keep this alphabetized 159 custom: 160 logcheck: 161 # Installed there by hack/verify-golangci-lint.sh. 162 path: ../_output/local/bin/logcheck.so 163 description: structured logging checker 164 original-url: k8s.io/logtools/logcheck 165 settings: 166 config: | 167 {{include "hack/logcheck.conf" | indent 10 | trim}} 168 forbidigo: 169 analyze-types: true 170 forbid: 171 - p: ^managedfields\.ExtractInto$ 172 pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$ 173 msg: should not be used because managedFields was removed 174 - p: \.Extract 175 pkg: ^k8s\.io/client-go/applyconfigurations/ 176 msg: should not be used because managedFields was removed 177 {{- if .Hints}} 178 - p: ^gomega\.BeTrue$ 179 pkg: ^github.com/onsi/gomega$ 180 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(...) }" 181 - p: ^gomega\.BeFalse$ 182 pkg: ^github.com/onsi/gomega$ 183 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(...) }" 184 {{- end}} 185 {{- if .Base }} 186 gocritic: 187 enabled-checks: 188 - equalFold 189 - boolExprSimplify 190 {{- end}} 191 revive: 192 # Only these rules are enabled. 193 rules: 194 - name: exported 195 arguments: 196 - disableStutteringCheck 197 staticcheck: 198 checks: 199 - "all" 200 {{- if .Base }} 201 - "-SA1019" # TODO(fix) Using a deprecated function, variable, constant or field 202 - "-SA2002" # TODO(fix) Called testing.T.FailNow or SkipNow in a goroutine, which isn’t allowed 203 {{- end}} 204 {{- if .Base }} 205 stylecheck: 206 checks: 207 - "ST1019" # Importing the same package multiple times 208 {{- end}}