version: '2'
run:
  timeout: 15m
  build-tags:
    - test
linters:
  default: none
  enable:
    - asciicheck
    - bidichk
    - bodyclose
    - contextcheck
    - depguard
    - dogsled
    - durationcheck
    - errcheck
    - errchkjson
    - errorlint
    - forbidigo
    - forcetypeassert
    - gochecknoinits
    - gocritic
    - godot
    - goheader
    - gomoddirectives
    - gomodguard_v2
    - goprintffuncname
    - govet
    - importas
    - ineffassign
    - makezero
    - misspell
    - mnd
    - nolintlint
    - revive
    - rowserrcheck
    - sqlclosecheck
    - staticcheck
    - unconvert
    - unparam
    - unused
    - usetesting
    - wastedassign
    - whitespace
    - zerologlint
  settings:
    depguard:
      rules:
        agent:
          list-mode: lax
          files:
            - '**/agent/*.go'
            - '**/agent/**/*.go'
            - '**/cmd/agent/*.go'
            - '**/cmd/agent/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
            - pkg: go.woodpecker-ci.org/woodpecker/v3/woodpecker-go/woodpecker
        cli:
          list-mode: lax
          files:
            - '**/cli/*.go'
            - '**/cli/**/*.go'
            - '**/cmd/cli/*.go'
            - '**/cmd/cli/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/rpc
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
        pipeline:
          list-mode: lax
          files:
            - '!**/cli/pipeline/*.go'
            - '!**/cli/pipeline/**/*.go'
            - '!**/server/pipeline/*.go'
            - '!**/server/pipeline/**/*.go'
            - '**/pipeline/*.go'
            - '**/pipeline/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd
            - pkg: go.woodpecker-ci.org/woodpecker/v3/rpc
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
        server:
          list-mode: lax
          files:
            - '**/cmd/server/*.go'
            - '**/cmd/server/**/*.go'
            - '**/server/*.go'
            - '**/server/**/*.go'
            - '**/web/*.go'
            - '**/web/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/backend
            - pkg: go.woodpecker-ci.org/woodpecker/v3/woodpecker-go/woodpecker
        rpc:
          list-mode: lax
          files:
            - '!**/agent/rpc/*.go'
            - '!**/agent/rpc/**/*.go'
            - '!**/server/rpc/*.go'
            - '!**/server/rpc/**/*.go'
            - '**/rpc/*.go'
            - '**/rpc/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
        shared:
          list-mode: lax
          files:
            - '!**/pipeline/shared/*.go'
            - '!**/pipeline/shared/**/*.go'
            - '**/shared/*.go'
            - '**/shared/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd
            - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline
            - pkg: go.woodpecker-ci.org/woodpecker/v3/rpc
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
        woodpecker-go:
          list-mode: lax
          files:
            - '**/woodpecker-go/woodpecker/*.go'
            - '**/woodpecker-go/woodpecker/**/*.go'
          deny:
            - pkg: go.woodpecker-ci.org/woodpecker/v3/agent
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cli
            - pkg: go.woodpecker-ci.org/woodpecker/v3/cmd
            - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline
            - pkg: go.woodpecker-ci.org/woodpecker/v3/rpc
            - pkg: go.woodpecker-ci.org/woodpecker/v3/server
            - pkg: go.woodpecker-ci.org/woodpecker/v3/shared
            - pkg: go.woodpecker-ci.org/woodpecker/v3/web
    errorlint:
      errorf-multi: true
    forbidigo:
      forbid:
        - pattern: context\.WithCancel$
        - pattern: ^print.*$
        - pattern: panic
        - pattern: ^log.Fatal().*$
    godot:
      scope: toplevel
      exclude:
        - '^\s*cSpell:'
        - '^\s*TODO:'
      capital: true
      period: true
    importas:
      no-extra-aliases: true
      alias:
        # stdlib
        - pkg: log
          alias: std_log

        # grpc / protobuf
        - pkg: google.golang.org/grpc/metadata
          alias: grpc_metadata
        - pkg: google.golang.org/grpc/credentials
          alias: grpc_credentials
        - pkg: google.golang.org/protobuf/proto
          alias: grpc_proto

        # woodpecker internal
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/backend/types
          alias: backend_types
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/errors
          alias: pipeline_errors
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/runtime
          alias: pipeline_runtime
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/utils
          alias: pipeline_utils
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/store/types
          alias: store_types
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/forge/types
          alias: forge_types
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/log
          alias: service_log
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/rpc
          alias: server_rpc
        - pkg: go.woodpecker-ci.org/woodpecker/v3/agent/rpc
          alias: agent_rpc
        - pkg: go.woodpecker-ci.org/woodpecker/v3/shared/utils
          alias: shared_utils
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/metadata
          alias: pipeline_metadata
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/yaml/types/base
          alias: yaml_base_types
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/frontend/yaml/types
          alias: yaml_types
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/cron
          alias: cron_scheduler

        # mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/secret/mocks
          alias: secret_service_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/registry/mocks
          alias: registry_service_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/mocks
          alias: manager_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/forge/mocks
          alias: forge_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/pipeline/tracing/mocks
          alias: tracer_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/queue/mocks
          alias: queue_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/store/mocks
          alias: store_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/config/mocks
          alias: config_service_mocks
        - pkg: go.woodpecker-ci.org/woodpecker/v3/server/services/log/mocks
          alias: log_mocks

        # kubernetes
        - pkg: k8s.io/api/core/v1
          alias: kube_core_v1
        - pkg: k8s.io/apimachinery/pkg/apis/meta/v1
          alias: kube_meta_v1
        - pkg: k8s.io/apimachinery/pkg/api/errors
          alias: kube_errors
        - pkg: k8s.io/client-go/tools/clientcmd
          alias: kube_client_cmd

        # docker
        - pkg: github.com/docker/cli/cli/config/types
          alias: docker_config_types

        # misc third-party
        - pkg: github.com/swaggo/files
          alias: swaggo_files
        - pkg: github.com/swaggo/gin-swagger
          alias: swaggo_gin_swagger
        - pkg: xorm.io/xorm/log
          alias: xlog
        - pkg: github.com/tink-crypto/tink-go/v2/insecurecleartextkeyset
          alias: insecure_clear_text_keyset
        - pkg: github.com/migueleliasweb/go-github-mock/src/mock
          alias: github_mock
        - pkg: gitlab.com/gitlab-org/api/client-go/v2
          alias: gitlab
    misspell:
      locale: US
    mnd:
      ignored-numbers:
        - '0o600'
        - '0o660'
        - '0o644'
        - '0o755'
        - '0o700'
      ignored-functions:
        - make
        - time.*
        - strings.Split
        - callerName
        - random.GetRandomBytes
    revive:
      rules:
        - name: var-naming
          arguments:
            - []
            - []
            - - skipPackageNameChecks: true
  exclusions:
    generated: lax
    presets:
      - comments
      - common-false-positives
      - legacy
      - std-error-handling
    rules:
      - linters:
          - mnd
        path: fixtures|cmd/agent/flags.go|cmd/server/flags.go|pipeline/backend/kubernetes/flags.go|_test.go
    paths:
      - third_party$
      - builtin$
      - examples$
formatters:
  enable:
    - gci
    - gofmt
    - gofumpt
  settings:
    gci:
      sections:
        - standard
        - default
        - prefix(go.woodpecker-ci.org/woodpecker)
      custom-order: true
    gofmt:
      simplify: true
      rewrite-rules:
        - pattern: interface{}
          replacement: any
    gofumpt:
      extra-rules: true
  exclusions:
    generated: lax
    paths:
      - third_party$
      - builtin$
      - examples$
