# golangci-lint configuration for Bose SoundTouch Go Library
# Compatible with golangci-lint v2.8.0
# See: https://golangci-lint.run/usage/configuration/

version: "2"

run:
  tests: true

linters:
  enable:
    # Default linters (merged staticcheck includes gosimple, stylecheck)
    - errcheck # Check for unchecked errors
    - staticcheck # Go static analysis (includes gosimple, stylecheck)
    - govet # Vet examines Go source code
    - ineffassign # Detect ineffectual assignments
    - unused # Check for unused constants, variables, functions and types

    # Additional useful linters for production code
    - misspell # Find commonly misspelled English words
    - unconvert # Remove unnecessary type conversions
    - unparam # Report unused function parameters
    - gocyclo # Compute cyclomatic complexities
    - gocritic # Most opinionated Go source code linter
    - nolintlint # Reports ill-formed or insufficient nolint directives
    - revive # Fast, configurable, extensible, flexible, and beautiful linter
    - whitespace # Tool for detection of leading and trailing whitespace
    - wsl_v5 # Whitespace Linter - Forces you to use empty lines
    - predeclared # Find code that shadows one of Go's predeclared identifiers
    - thelper # Detect golang test helpers without t.Helper() call
    - tparallel # Detect inappropriate usage of t.Parallel() method in tests
    - bodyclose # Check whether HTTP response body is closed successfully
    - nilerr # Find the code that returns nil even if it checks that the error is not nil
    - nilnil # Check that there is no simultaneous return of nil error and an invalid value
    - errchkjson # Check types passed to the json encoding functions
    - errorlint # Find code that will cause problems with the error wrapping scheme
    - contextcheck # Check the function whether use a non-inherited context

  exclusions:
    paths:
      - vendor
      - build
      - scripts
      - ".*\\.pb\\.go$"
      - ".*_gen\\.go$"

    rules:
      # Exclude some linters from running on tests files
      - path: _test\.go
        linters:
          - gocritic # Can be overly strict for test code
          - wsl # Whitespace less critical in tests
          - wsl_v5 # Whitespace less critical in tests
          - gocyclo # Complexity less critical in tests
          - govet # Avoid shadow warnings in tests
          - revive # Avoid exported/package-comments in tests
          - errcheck # Avoid mandatory error checks in tests
          - unparam # Often parameters are fixed in test setups

      # Exclude specific rules for generated files
      - path: ".*\\.pb\\.go$"
        linters:
          - all

      # Exclude some staticcheck messages
      - linters:
          - staticcheck
        text: "SA9003:" # Empty branch

      - linters:
          - staticcheck
        text: "SA1008: keys in http.Header are canonicalized"
        path: pkg/service/handlers/handlers_etag_test.go

      # Allow main functions to not check errors in examples
      - path: cmd/.*\.go
        text: "Error return value of.*is not checked"
        linters:
          - errcheck

  settings:
    errcheck:
      check-type-assertions: true
      check-blank: false
      exclude-functions:
        - (*os.File).Close
        - (*bytes.Buffer).Write
        - (*bytes.Buffer).WriteString

    govet:
      enable:
        - shadow
      enable-all: true
      disable:
        - fieldalignment # Can be overly aggressive

    gocyclo:
      min-complexity: 20

    gocritic:
      enabled-checks:
        - boolExprSimplify
        - builtinShadow
        - emptyFallthrough
        - equalFold
        - hexLiteral
        - indexAlloc
        - initClause
        - methodExprCall
        - nestingReduce
        - nilValReturn
        - paramTypeCombine
        - ptrToRefParam
        - rangeExprCopy
        - rangeValCopy
        - stringXbytes
        - typeAssertChain
        - weakCond
        - yodaStyleExpr

    revive:
      rules:
        - name: var-naming
          arguments:
            [["ID", "URL", "HTTP", "JSON", "XML", "API", "UUID", "SQL"], []]
        - name: exported
        - name: blank-imports
        - name: context-as-argument
        - name: context-keys-type
        - name: dot-imports
        - name: empty-block
        - name: error-naming
        - name: error-return
        - name: error-strings
        - name: errorf
        - name: increment-decrement
        - name: indent-error-flow
        - name: package-comments
        - name: range
        - name: receiver-naming
        - name: redefines-builtin-id
        - name: superfluous-else
        - name: time-naming
        - name: unexported-return
        - name: unreachable-code
        - name: unused-parameter
        - name: var-declaration
        - name: waitgroup-by-value

    whitespace:
      multi-if: false
      multi-func: false

    wsl_v5:
      allow-first-in-block: true
      allow-whole-block: false
      branch-max-lines: 2

    predeclared:
      ignore:
        - new
        - int

formatters:
  enable:
    - gofmt # Check whether code was gofmt-ed
    - goimports # Check import sorting

  exclusions:
    paths:
      - vendor
      - build
      - scripts
      - ".*\\.pb\\.go$"
      - ".*_gen\\.go$"

output:
  formats:
    text:
      path: stdout
      colors: true
  show-stats: true

severity:
  default: error
