version: "2"
linters:
  default: all
  disable:
    - depguard # too restrictive for us
    - errcheck # sometimes we ignore errors intentionally
    - err113 # we are OK with untyped errors
    - exhaustive # this is not Rust yet
    - exhaustruct # we often use partial struct literals
    - gocritic # mostly false positives
    - godot # too noisy
    - godox # we use TODOs intentionally
    - gochecknoglobals # we use global pools
    - gocyclo # cyclo is enough
    - gochecknoinits # init() is still used
    - ireturn # return interface is normal
    - mnd # many false positives on things like SplitN
    - nilnil # we sometimes return nil, nil
    - nonamedreturns # we sometimes use named returns for clarity
    - noinlineerr # we use inline errors extensively
    - paralleltest # we can't always use t.Parallel()
    - varnamelen # that's not for linter to decide
    - wsl # deprecated

    # NOTE: this is legit, but too much conflicts with existing codebase
    - perfsprint
    - nlreturn
    - nestif # too much noise for now, but needs fixing
    - noctx
    - funlen # needs fixing
    - contextcheck
    - wrapcheck # we are OK with some untyped errors
    - wsl_v5

  settings:
    gosec:
      excludes:
        - G104 # ignoring errors on Close is acceptable
        - G304 # well...

    funcorder:
      alphabetical: false

    revive:
      rules:
        - name: package-comments
          disabled: true
        - name: exported # should be reviewed at some point
          disabled: true

  exclusions:
    rules:
      # can be used
      - linters:
          - sloglint
        path: ^logger

      # we use our own logic there
      - linters:
          - errorlint
        path: ^errctx

      # do not check test files extensively
      - linters:
          - funlen
          - forcetypeassert
          - goconst
          - gosec
          - funcorder # setup -> helpers -> test
        path: _test.go$|^xmlparser|storage/test_server.go|test_storage.go

      # these indicate complexity problems and should be refactored eventually
      - linters:
          - cyclop
        path: ^xmlparser|^vips|^storage|^processing|^options|^monitoring

      - linters:
          - cyclop
        path: asyncbuffer/buffer.go|cookies/cookies.go|fetcher/request.go|fetcher/transport/generichttp/generic_http.go

      - linters:
          - cyclop
        path: fetcher/transport/transport.go|httprange/httprange.go|handlers/processing/request.go

      - linters:
          - cyclop
        path: env/aws.go|imgproxy.go|testutil/equal_but_not_same.go|clientfeatures/detector.go

      - linters:
          - cyclop
        path: processing/request.go,asyncbuffer/buffer.go

      - linters:
          - gocognit
        path: ^processing|^storage|^xmlparser

      # this test needs extensive refactoring anyways
      - linters:
          - maintidx
          - dupl
        path: ^processing/processing_test.go

    paths:
      - .tmp
      - vendor
      - third_party$
      - builtin$
      - ^examples
      - ^config # remove once we done with the config

formatters:
  enable:
    - goimports
  exclusions:
    paths:
      - .tmp
      - vendor
      - third_party$
      - builtin$
      - examples$
