.golangci.yml

  1# See https://github.com/golangci/golangci-lint#config-file
  2run:
  3  issues-exit-code: 1 #Default
  4  tests: true #Default
  5
  6linters:
  7  # Disable everything by default so upgrades to not include new "default
  8  # enabled" linters.
  9  disable-all: true
 10  # Specifically enable linters we want to use.
 11  enable:
 12    - asasalint
 13    - bodyclose
 14    - depguard
 15    - errcheck
 16    - errorlint
 17    - godot
 18    - gofumpt
 19    - goimports
 20    - gosec
 21    - gosimple
 22    - govet
 23    - ineffassign
 24    - misspell
 25    - perfsprint
 26    - revive
 27    - staticcheck
 28    - testifylint
 29    - typecheck
 30    - unconvert
 31    - unused
 32    - unparam
 33    - usestdlibvars
 34    - usetesting
 35
 36issues:
 37  # Maximum issues count per one linter.
 38  # Set to 0 to disable.
 39  # Default: 50
 40  # Setting to unlimited so the linter only is run once to debug all issues.
 41  max-issues-per-linter: 0
 42  # Maximum count of issues with the same text.
 43  # Set to 0 to disable.
 44  # Default: 3
 45  # Setting to unlimited so the linter only is run once to debug all issues.
 46  max-same-issues: 0
 47  # Excluding configuration per-path, per-linter, per-text and per-source.
 48  exclude-rules:
 49    # TODO: Having appropriate comments for exported objects helps development,
 50    # even for objects in internal packages. Appropriate comments for all
 51    # exported objects should be added and this exclusion removed.
 52    - path: '.*internal/.*'
 53      text: "exported (method|function|type|const) (.+) should have comment or be unexported"
 54      linters:
 55        - revive
 56    # Yes, they are, but it's okay in a test.
 57    - path: _test\.go
 58      text: "exported func.*returns unexported type.*which can be annoying to use"
 59      linters:
 60        - revive
 61    # Example test functions should be treated like main.
 62    - path: example.*_test\.go
 63      text: "calls to (.+) only in main[(][)] or init[(][)] functions"
 64      linters:
 65        - revive
 66    # It's okay to not run gosec and perfsprint in a test.
 67    - path: _test\.go
 68      linters:
 69        - gosec
 70        - perfsprint
 71    # Ignoring gosec G404: Use of weak random number generator (math/rand instead of crypto/rand)
 72    # as we commonly use it in tests and examples.
 73    - text: "G404:"
 74      linters:
 75        - gosec
 76    # Ignoring gosec G402: TLS MinVersion too low
 77    # as the https://pkg.go.dev/crypto/tls#Config handles MinVersion default well.
 78    - text: "G402: TLS MinVersion too low."
 79      linters:
 80        - gosec
 81  include:
 82    # revive exported should have comment or be unexported.
 83    - EXC0012
 84    # revive package comment should be of the form ...
 85    - EXC0013
 86
 87linters-settings:
 88  depguard:
 89    rules:
 90      non-tests:
 91        files:
 92          - "!$test"
 93          - "!**/*test/*.go"
 94          - "!**/internal/matchers/*.go"
 95        deny:
 96          - pkg: "testing"
 97          - pkg: "github.com/stretchr/testify"
 98          - pkg: "crypto/md5"
 99          - pkg: "crypto/sha1"
100          - pkg: "crypto/**/pkix"
101      auto/sdk:
102        files:
103          - "!internal/global/trace.go"
104          - "~internal/global/trace_test.go"
105        deny:
106          - pkg: "go.opentelemetry.io/auto/sdk"
107            desc: Do not use SDK from automatic instrumentation.
108      otlp-internal:
109        files:
110          - "!**/exporters/otlp/internal/**/*.go"
111        deny:
112          - pkg: "go.opentelemetry.io/otel/exporters/otlp/internal"
113            desc: Do not use cross-module internal packages.
114      otlptrace-internal:
115        files:
116          - "!**/exporters/otlp/otlptrace/*.go"
117          - "!**/exporters/otlp/otlptrace/internal/**.go"
118        deny:
119          - pkg: "go.opentelemetry.io/otel/exporters/otlp/otlptrace/internal"
120            desc: Do not use cross-module internal packages.
121      otlpmetric-internal:
122        files:
123          - "!**/exporters/otlp/otlpmetric/internal/*.go"
124          - "!**/exporters/otlp/otlpmetric/internal/**/*.go"
125        deny:
126          - pkg: "go.opentelemetry.io/otel/exporters/otlp/otlpmetric/internal"
127            desc: Do not use cross-module internal packages.
128      otel-internal:
129        files:
130          - "**/sdk/*.go"
131          - "**/sdk/**/*.go"
132          - "**/exporters/*.go"
133          - "**/exporters/**/*.go"
134          - "**/schema/*.go"
135          - "**/schema/**/*.go"
136          - "**/metric/*.go"
137          - "**/metric/**/*.go"
138          - "**/bridge/*.go"
139          - "**/bridge/**/*.go"
140          - "**/trace/*.go"
141          - "**/trace/**/*.go"
142          - "**/log/*.go"
143          - "**/log/**/*.go"
144        deny:
145          - pkg: "go.opentelemetry.io/otel/internal$"
146            desc: Do not use cross-module internal packages.
147          - pkg: "go.opentelemetry.io/otel/internal/attribute"
148            desc: Do not use cross-module internal packages.
149          - pkg: "go.opentelemetry.io/otel/internal/internaltest"
150            desc: Do not use cross-module internal packages.
151          - pkg: "go.opentelemetry.io/otel/internal/matchers"
152            desc: Do not use cross-module internal packages.
153  godot:
154    exclude:
155      # Exclude links.
156      - '^ *\[[^]]+\]:'
157      # Exclude sentence fragments for lists.
158      - '^[ ]*[-•]'
159      # Exclude sentences prefixing a list.
160      - ':$'
161  goimports:
162    local-prefixes: go.opentelemetry.io
163  misspell:
164    locale: US
165    ignore-words:
166      - cancelled
167  perfsprint:
168    err-error: true
169    errorf: true
170    int-conversion: true
171    sprintf1: true
172    strconcat: true
173  revive:
174    # Sets the default failure confidence.
175    # This means that linting errors with less than 0.8 confidence will be ignored.
176    # Default: 0.8
177    confidence: 0.01
178    # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
179    rules:
180      - name: blank-imports
181      - name: bool-literal-in-expr
182      - name: constant-logical-expr
183      - name: context-as-argument
184        disabled: true
185        arguments:
186          - allowTypesBefore: "*testing.T"
187      - name: context-keys-type
188      - name: deep-exit
189      - name: defer
190        arguments:
191          - ["call-chain", "loop"]
192      - name: dot-imports
193      - name: duplicated-imports
194      - name: early-return
195        arguments:
196          - "preserveScope"
197      - name: empty-block
198      - name: empty-lines
199      - name: error-naming
200      - name: error-return
201      - name: error-strings
202      - name: errorf
203      - name: exported
204        arguments:
205          - "sayRepetitiveInsteadOfStutters"
206      - name: flag-parameter
207      - name: identical-branches
208      - name: if-return
209      - name: import-shadowing
210      - name: increment-decrement
211      - name: indent-error-flow
212        arguments:
213          - "preserveScope"
214      - name: package-comments
215      - name: range
216      - name: range-val-in-closure
217      - name: range-val-address
218      - name: redefines-builtin-id
219      - name: string-format
220        arguments:
221          - - panic
222            - '/^[^\n]*$/'
223            - must not contain line breaks
224      - name: struct-tag
225      - name: superfluous-else
226        arguments:
227          - "preserveScope"
228      - name: time-equal
229      - name: unconditional-recursion
230      - name: unexported-return
231      - name: unhandled-error
232        arguments:
233          - "fmt.Fprint"
234          - "fmt.Fprintf"
235          - "fmt.Fprintln"
236          - "fmt.Print"
237          - "fmt.Printf"
238          - "fmt.Println"
239      - name: unnecessary-stmt
240      - name: useless-break
241      - name: var-declaration
242      - name: var-naming
243        arguments:
244          - ["ID"] # AllowList
245          - ["Otel", "Aws", "Gcp"] # DenyList
246      - name: waitgroup-by-value
247  testifylint:
248    enable-all: true
249    disable:
250      - float-compare
251      - go-require
252      - require-error