version: "2"
run:
  issues-exit-code: 1
  tests: true
linters:
  default: none
  enable:
    - asasalint
    - bodyclose
    - copyloopvar
    - depguard
    - errcheck
    - errorlint
    - forbidigo
    - gocritic
    - godot
    - gosec
    - govet
    - ineffassign
    - intrange
    - modernize
    - misspell
    - noctx
    - nolintlint
    - perfsprint
    - revive
    - staticcheck
    - testifylint
    - unconvert
    - unparam
    - unused
    - usestdlibvars
    - usetesting
  settings:
    depguard:
      rules:
        no-sdk-instrumentation:
          files:
            - '**/*/{bridges,instrumentation}/**/*.go'
            - '!$test'
            - "!**/*/bridges/prometheus/*.go" # prometheus bridge is meant to use the SDK
            - "!**/*/instrumentation/runtime/*.go" # runtime instrumentation is meant to use the SDK
            - '!**/*test/*.go'
            - '!**/*test/**/*.go'
            - '!**/*example/*.go'
            - '!**/*example/**/*.go'
          deny:
            - pkg: go.opentelemetry.io/otel/sdk
              desc: Bridges and instrumentations should not use the SDKs, except in test or example modules
        non-tests:
          files:
            - '!$test'
            - '!**/*test/*.go'
          deny:
            - pkg: testing
            - pkg: github.com/stretchr/testify
            - pkg: crypto/md5
            - pkg: crypto/sha1
            - pkg: crypto/**/pkix
        semconv:
          list-mode: lax
          deny:
            - pkg: go.opentelemetry.io/otel/semconv
              desc: Use go.opentelemetry.io/otel/semconv/v1.40.0 instead. If a newer semconv version has been released, update the depguard rule.
          allow:
            - go.opentelemetry.io/otel/semconv/v1.21.0 # still used by otelmongo
            - go.opentelemetry.io/otel/semconv/v1.40.0
    forbidigo:
      forbid:
        - pattern: '^trace\.Span\.RecordError$'
          pkg: '^go\.opentelemetry\.io/otel/trace$'
          msg: "Span.RecordError is not allowed, Reference: https://github.com/open-telemetry/opentelemetry-go-contrib/pull/8386"
      exclude-godoc-examples: false
      analyze-types: true
    gocritic:
      disabled-checks:
        - appendAssign
        - exitAfterDefer
        - exposedSyncMutex
        - hugeParam
        - unnamedResult
      enable-all: true
    godot:
      exclude:
        # Exclude sentence fragments for lists.
        - ^[ ]*[-•]
        # Exclude sentences prefixing a list.
        - :$
    misspell:
      locale: US
      ignore-rules:
        - cancelled
    nolintlint:
      require-explanation: true
      require-specific: true
    perfsprint:
      int-conversion: true
      err-error: true
      errorf: true
      sprintf1: true
      strconcat: true
    revive:
      # Sets the default failure confidence.
      # This means that linting errors with less than 0.8 confidence will be ignored.
      # Default: 0.8
      confidence: 0.01
      # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md
      rules:
        - name: blank-imports
        - name: bool-literal-in-expr
        - name: constant-logical-expr
        # TODO (#2877) re-enable linter when it is compatible. https://github.com/golangci/golangci-lint/issues/3280
        - name: context-as-argument
          disabled: true
          arguments:
            - allow-types-before: "*testing.T"
        - name: context-keys-type
        - name: deep-exit
        - name: defer
          arguments:
            - ["call-chain", "loop"]
        - name: dot-imports
        - name: duplicated-imports
        - name: early-return
        - name: empty-block
        - name: empty-lines
        - name: error-naming
        - name: error-return
        - name: error-strings
        - name: errorf
        - name: exported
          arguments:
            - "say-repetitive-instead-of-stutters"
        - name: flag-parameter
        - name: identical-branches
        - name: if-return
        - name: increment-decrement
        - name: indent-error-flow
        - name: import-shadowing
        - name: package-comments
        - name: range
        - name: range-val-in-closure
        - name: range-val-address
        - name: redefines-builtin-id
        - name: string-format
          arguments:
            - - panic
              - '/^[^\n]*$/'
              - must not contain line breaks
        - name: struct-tag
        - name: superfluous-else
        - name: time-equal
        - name: unconditional-recursion
        - name: unexported-return
        - name: unused-parameter
        - name: unused-receiver
        - name: unhandled-error
          arguments:
            - "fmt.Fprint"
            - "fmt.Fprintf"
            - "fmt.Fprintln"
            - "fmt.Print"
            - "fmt.Printf"
            - "fmt.Println"
        - name: unnecessary-stmt
        - name: use-any
        - name: useless-break
        - name: var-declaration
        - name: var-naming
          arguments:
            - ["ID"] # AllowList
            - ["Otel", "Aws", "Gcp"] # DenyList
            - - skip-initialism-name-checks: true
                upper-case-const: true
                skip-package-name-checks: true
                skip-package-name-collision-with-go-std: true
        - name: waitgroup-by-value
    testifylint:
      enable-all: true
      disable:
        - float-compare
        - require-error
    usetesting:
      context-background: true
      context-todo: true
  exclusions:
    generated: lax
    presets:
      - common-false-positives
      - legacy
      - std-error-handling
    rules:
      # TODO: Having appropriate comments for exported objects helps development,
      # even for objects in internal packages. Appropriate comments for all
      # exported objects should be added and this exclusion removed.
      - linters:
          - revive
        path: .*internal/.*
        text: exported (method|function|type|const) (.+) should have comment or be unexported
      # Yes, they are, but it's okay in a test.
      - linters:
          - revive
        path: _test\.go
        text: exported func.*returns unexported type.*which can be annoying to use
      # Example test functions should be treated like main.
      - linters:
          - revive
        path: example.*_test\.go
        text: calls to (.+) only in main[(][)] or init[(][)] functions
      # It's okay to not run gosec and perfsprint in a test.
      - linters:
          - gosec
          - perfsprint
          - usestdlibvars
        path: _test\.go
      # Ignoring gosec G402: TLS MinVersion too low
      # as the https://pkg.go.dev/crypto/tls#Config handles MinVersion default well.
      - linters:
          - gosec
        path: config/*.go
        text: 'G402: TLS MinVersion too low.'
issues:
  max-issues-per-linter: 0
  max-same-issues: 0
formatters:
  enable:
    - gofumpt
    - goimports
  settings:
    gofumpt:
      extra-rules: true
    goimports:
      local-prefixes:
        - go.opentelemetry.io/contrib
  exclusions:
    generated: lax
