istio.io/istio@v0.0.0-20240520182934-d79c90f27776/common/config/.golangci.yml (about) 1 # WARNING: DO NOT EDIT, THIS FILE IS PROBABLY A COPY 2 # 3 # The original version of this file is located in the https://github.com/istio/common-files repo. 4 # If you're looking at this file in a different repo and want to make a change, please go to the 5 # common-files repo, make the change there and check it in. Then come back to this repo and run 6 # "make update-common". 7 8 run: 9 # Timeout for analysis, e.g. 30s, 5m. 10 # Default: 1m 11 timeout: 20m 12 build-tags: 13 - integ 14 - integfuzz 15 linters: 16 disable-all: true 17 enable: 18 - errcheck 19 - exportloopref 20 - depguard 21 - gocritic 22 - gofumpt 23 - goimports 24 - revive 25 - gosimple 26 - govet 27 - ineffassign 28 - lll 29 - misspell 30 - staticcheck 31 - stylecheck 32 - typecheck 33 - unconvert 34 - unparam 35 - unused 36 - gci 37 - gosec 38 fast: false 39 linters-settings: 40 errcheck: 41 # report about not checking of errors in type assertions: `a := b.(MyStruct)`; 42 # default is false: such cases aren't reported by default. 43 check-type-assertions: false 44 # report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`; 45 # default is false: such cases aren't reported by default. 46 check-blank: false 47 govet: 48 disable: 49 # report about shadowed variables 50 - shadow 51 goimports: 52 # put imports beginning with prefix after 3rd-party packages; 53 # it's a comma-separated list of prefixes 54 local-prefixes: istio.io/ 55 misspell: 56 # Correct spellings using locale preferences for US or UK. 57 # Default is to use a neutral variety of English. 58 # Setting locale to US will correct the British spelling of 'colour' to 'color'. 59 locale: US 60 ignore-words: 61 - cancelled 62 lll: 63 # max line length, lines longer will be reported. Default is 120. 64 # '\t' is counted as 1 character by default, and can be changed with the tab-width option 65 line-length: 160 66 # tab width in spaces. Default to 1. 67 tab-width: 1 68 revive: 69 ignore-generated-header: false 70 severity: "warning" 71 confidence: 0.0 72 rules: 73 - name: blank-imports 74 - name: context-keys-type 75 - name: time-naming 76 - name: var-declaration 77 - name: unexported-return 78 - name: errorf 79 - name: context-as-argument 80 - name: dot-imports 81 - name: error-return 82 - name: error-strings 83 - name: error-naming 84 - name: increment-decrement 85 - name: var-naming 86 - name: package-comments 87 - name: range 88 - name: receiver-naming 89 - name: indent-error-flow 90 - name: superfluous-else 91 - name: modifies-parameter 92 - name: unreachable-code 93 - name: struct-tag 94 - name: constant-logical-expr 95 - name: bool-literal-in-expr 96 - name: redefines-builtin-id 97 - name: imports-blacklist 98 - name: range-val-in-closure 99 - name: range-val-address 100 - name: waitgroup-by-value 101 - name: atomic 102 - name: call-to-gc 103 - name: duplicated-imports 104 - name: string-of-int 105 - name: defer 106 arguments: 107 - - "call-chain" 108 - name: unconditional-recursion 109 - name: identical-branches 110 # the following rules can be enabled in the future 111 # - name: empty-lines 112 # - name: confusing-results 113 # - name: empty-block 114 # - name: get-return 115 # - name: confusing-naming 116 # - name: unexported-naming 117 # - name: early-return 118 # - name: unused-parameter 119 # - name: unnecessary-stmt 120 # - name: deep-exit 121 # - name: import-shadowing 122 # - name: modifies-value-receiver 123 # - name: unused-receiver 124 # - name: bare-return 125 # - name: flag-parameter 126 # - name: unhandled-error 127 # - name: if-return 128 unparam: 129 # Inspect exported functions, default is false. Set to true if no external program/library imports your code. 130 # XXX: if you enable this setting, unparam will report a lot of false-positives in text editors: 131 # if it's called for subdir of a project it can't find external interfaces. All text editor integrations 132 # with golangci-lint call it on a directory with the changed file. 133 check-exported: false 134 gci: 135 sections: 136 - standard # Captures all standard packages if they do not match another section. 137 - default # Contains all imports that could not be matched to another section type. 138 - prefix(istio.io/) # Groups all imports with the specified Prefix. 139 gocritic: 140 # Disable all checks. 141 # Default: false 142 disable-all: true 143 # Which checks should be enabled in addition to default checks. Since we don't want 144 # all of the default checks, we do the disable-all first. 145 enabled-checks: 146 - appendCombine 147 - argOrder 148 - assignOp 149 - badCond 150 - boolExprSimplify 151 - builtinShadow 152 - captLocal 153 - caseOrder 154 - codegenComment 155 - commentedOutCode 156 - commentedOutImport 157 - defaultCaseOrder 158 - deprecatedComment 159 - docStub 160 - dupArg 161 - dupBranchBody 162 - dupCase 163 - dupSubExpr 164 - elseif 165 - emptyFallthrough 166 - equalFold 167 - flagDeref 168 - flagName 169 - hexLiteral 170 - indexAlloc 171 - initClause 172 - methodExprCall 173 - nilValReturn 174 - octalLiteral 175 - offBy1 176 - rangeExprCopy 177 - regexpMust 178 - sloppyLen 179 - stringXbytes 180 - switchTrue 181 - typeAssertChain 182 - typeSwitchVar 183 - typeUnparen 184 - underef 185 - unlambda 186 - unnecessaryBlock 187 - unslice 188 - valSwap 189 - weakCond 190 depguard: 191 rules: 192 DenyGogoProtobuf: 193 files: 194 - $all 195 deny: 196 - pkg: github.com/gogo/protobuf 197 desc: "gogo/protobuf is deprecated, use golang/protobuf" 198 # deny for all go files 199 AllGoFiles: 200 files: 201 - $all 202 deny: 203 - pkg: golang.org/x/net/http2/h2c 204 desc: "h2c.NewHandler is unsafe; use wrapper istio.io/istio/pkg/h2c" 205 - pkg: github.com/golang/protobuf/jsonpb 206 desc: "don't use the jsonpb package directly; use util/protomarshal instead" 207 - pkg: google.golang.org/protobuf/encoding/protojson 208 desc: "don't use the protojson package directly; use util/protomarshal instead" 209 - pkg: gomodules.xyz/jsonpatch/v3 210 desc: "don't use v3; v2 is orders of magnitude higher performance" 211 - pkg: k8s.io/apimachinery/pkg/util/sets 212 desc: "use istio.io/istio/pkg/util/sets" 213 - pkg: k8s.io/utils/env 214 desc: "use istio.io/istio/pkg/env" 215 - pkg: k8s.io/utils/strings/slices 216 desc: "use istio.io/istio/pkg/slices" 217 - pkg: k8s.io/utils/pointer 218 desc: "use istio.io/istio/pkg/ptr" 219 - pkg: go.opencensus.io 220 desc: "do not use OpenCensus; use OpenTelemetry instead" 221 - pkg: golang.org/x/exp/maps 222 desc: "do not use golang.org/x/exp/maps; use istio.io/istio/pkg/maps instead" 223 - pkg: maps 224 desc: "do not use maps; use istio.io/istio/pkg/maps instead" 225 - pkg: golang.org/x/exp/slices 226 desc: "do not use golang.org/x/exp/slices; use istio.io/istio/pkg/slices instead" 227 - pkg: slices 228 desc: "do not use slices; use istio.io/istio/pkg/slices instead" 229 DenyOperatorAndIstioctl: 230 files: 231 # Tests can do anything 232 - "!$test" 233 # Main code should only be used by appropriate binaries 234 - "!**/operator/**" 235 - "!**/istioctl/**" 236 - "!**/tools/bug-report/**" 237 # This should only really import operator API, but that is hard to express without a larger refactoring 238 - "!**/pkg/kube/**" 239 - "!**/pkg/url/**" 240 - "!**/pkg/test/framework/**" 241 - "!**/tests/fuzz/**" 242 deny: 243 - pkg: istio.io/istio/operator 244 desc: "operator should not be imported" 245 - pkg: istio.io/istio/istioctl 246 desc: "istioctl should not be imported" 247 DenyOpenTelemetry: 248 files: 249 - $all 250 - "!**/pkg/monitoring/**" 251 - "!**/pkg/tracing/**" 252 deny: 253 - pkg: go.opentelemetry.io/otel 254 desc: "do not use OpenTelemetry directly; use pkg/monitoring" 255 - pkg: go.opentelemetry.io/otel/metric 256 desc: "do not use OpenTelemetry directly; use pkg/monitoring" 257 DenyProtobufV1: 258 files: 259 - $all 260 deny: 261 - pkg: github.com/golang/protobuf/ptypes 262 desc: "do not use github.com/golang/protobuf/ptypes; use google.golang.org/protobuf/types/known instead" 263 gosec: 264 includes: 265 - G401 266 - G402 267 - G404 268 issues: 269 # List of regexps of issue texts to exclude, empty list by default. 270 # But independently from this option we use default exclude patterns, 271 # it can be disabled by `exclude-use-default: false`. To list all 272 # excluded by default patterns execute `golangci-lint run --help` 273 exclude: 274 - composite literal uses unkeyed fields 275 # Which dirs to exclude: issues from them won't be reported. 276 # Can use regexp here: `generated.*`, regexp is applied on full path, 277 # including the path prefix if one is set. 278 # Default dirs are skipped independently of this option's value (see exclude-dirs-use-default). 279 # "/" will be replaced by current OS file path separator to properly work on Windows. 280 # Default: [] 281 exclude-dirs: 282 - genfiles$ 283 - vendor$ 284 # Which files to exclude: they will be analyzed, but issues from them won't be reported. 285 # There is no need to include all autogenerated files, 286 # we confidently recognize autogenerated files. 287 # If it's not, please let us know. 288 # "/" will be replaced by current OS file path separator to properly work on Windows. 289 # Default: [] 290 exclude-files: 291 - ".*\\.pb\\.go" 292 - ".*\\.gen\\.go" 293 exclude-rules: 294 # Exclude some linters from running on test files. 295 - path: _test\.go$|^tests/|^samples/ 296 linters: 297 - errcheck 298 - maligned 299 - path: _test\.go$ 300 text: "dot-imports: should not use dot imports" 301 # We need to use the deprecated module since the jsonpb replacement is not backwards compatible. 302 - linters: 303 - staticcheck 304 text: "SA1019: package github.com/golang/protobuf/jsonpb" 305 - linters: 306 - staticcheck 307 text: 'SA1019: "github.com/golang/protobuf/jsonpb"' 308 # This is not helpful. The new function is not very usable and the current function will not be removed 309 - linters: 310 - staticcheck 311 text: 'SA1019: grpc.Dial is deprecated: use NewClient instead' 312 - linters: 313 - staticcheck 314 text: 'SA1019: grpc.DialContext is deprecated: use NewClient instead' 315 # Independently from option `exclude` we use default exclude patterns, 316 # it can be disabled by this option. To list all 317 # excluded by default patterns execute `golangci-lint run --help`. 318 # Default value for this option is true. 319 exclude-use-default: true 320 # Maximum issues count per one linter. 321 # Set to 0 to disable. 322 # Default: 50 323 max-issues-per-linter: 0 324 # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. 325 max-same-issues: 0