linters:
  enable:
    - depguard      # Checks for imports that shouldn't be used.
    - exportloopref # Checks for pointers to enclosing loop variables
    - gofmt
    - goimports
    - gosec
    - ineffassign
    - misspell
    - nolintlint
    - revive
    - staticcheck
    - tenv # Detects using os.Setenv instead of t.Setenv since Go 1.17
    - unconvert
    - unused
    - vet
    - dupword # Checks for duplicate words in the source code
  disable:
    - errcheck

issues:
  include:
    - EXC0002
  max-issues-per-linter: 0
  max-same-issues: 0

  exclude-dirs:
    - api
    - cluster
    - design
    - docs
    - docs/man
    - releases
    - reports
    - test # e2e scripts

  # Only using / doesn't work due to https://github.com/golangci/golangci-lint/issues/1398.
  exclude-rules:
    - path: 'cmd[\\/]containerd[\\/]builtins[\\/]'
      text: "blank-imports:"
    - path: 'contrib[\\/]fuzz[\\/]'
      text: "exported: func name will be used as fuzz.Fuzz"
    - path: 'archive[\\/]tarheader[\\/]'
      # conversion is necessary on Linux, unnecessary on macOS
      text: "unnecessary conversion"
    - linters:
        - revive
      text: "if-return"
    - linters:
        - revive
      text: "empty-block"
    - linters:
        - revive
      text: "superfluous-else"
    - linters:
        - revive
      text: "unused-parameter"
    - linters:
        - revive
      text: "unreachable-code"
    - linters:
        - revive
      text: "redefines-builtin-id"

    # FIXME temporarily suppress deprecation warnings for the logs package. See https://github.com/containerd/containerd/pull/9086
    - text: "SA1019: log\\.(G|L|Fields|Entry|RFC3339NanoFixed|Level|TraceLevel|DebugLevel|InfoLevel|WarnLevel|ErrorLevel|FatalLevel|PanicLevel|SetLevel|GetLevel|OutputFormat|TextFormat|JSONFormat|SetFormat|WithLogger|GetLogger)"
      linters:
        - staticcheck
    - text: "SA1019: logtest\\.WithT"
      linters:
        - staticcheck


linters-settings:
  depguard:
    rules:
      main:
        deny:
          - pkg: "github.com/containerd/containerd/log"
            desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
          - pkg: "github.com/containerd/containerd/platforms"
            desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
  gosec:
    # The following issues surfaced when `gosec` linter
    # was enabled. They are temporarily excluded to unblock
    # the existing workflow, but still to be addressed by
    # future works.
    excludes:
      - G204
      - G305
      - G306
      - G402
      - G404
      - G115

run:
  timeout: 8m
