Skip to content

Custom Linting

Configure golangci-lint for your project's specific needs.

Using Custom Configuration

Step 1: Create Configuration

Create .golangci.yml in your project root:

version: "2"

linters-settings:
  gocyclo:
    min-complexity: 20  # Override default

issues:
  exclude-dirs:
    - generated

Step 2: Reference in Workflow

jobs:
  lint:
    uses: go-gamma/actions/.github/workflows/lint.yml@v1
    with:
      config-path: '.golangci.yml'

Common Customizations

Increase Complexity Limits

For legacy or complex codebases:

linters-settings:
  gocyclo:
    min-complexity: 25
  gocognit:
    min-complexity: 40
  funlen:
    lines: 150

Exclude Directories

issues:
  exclude-dirs:
    - vendor
    - generated
    - internal/legacy
    - third_party

Exclude Specific Files

issues:
  exclude-rules:
    - path: _mock\.go$
      linters: [all]

    - path: internal/legacy/
      linters:
        - gocyclo
        - funlen

Disable Linters

linters:
  disable:
    - wrapcheck     # Too strict
    - exhaustive    # Not needed

Enable Additional Linters

linters:
  enable:
    - dupl          # Duplicate code
    - gochecknoinits # No init functions

Per-File Configuration

Suppress in Code

//nolint:errcheck
func riskyOperation() {
    file.Close()
}

Suppress with Reason

//nolint:gocyclo // Legacy code, refactoring planned
func complexFunction() {
    // ...
}

Suppress Specific Line

func example() {
    file.Close() //nolint:errcheck
}

Team Guidelines

issues:
  exclude-rules:
    # Test files are more lenient
    - path: _test\.go
      linters:
        - errcheck
        - funlen
        - gocyclo

    # Generated code
    - path: \.pb\.go$
      linters: [all]

    # Main packages
    - path: cmd/
      linters:
        - gochecknoglobals
Metric Default Recommended
Cyclomatic complexity 15 10-20
Cognitive complexity 20 15-30
Function length 100 80-150
Max issues 50 20-100

Debugging

Verbose Output

with:
  args: '-v'

List Enabled Linters

golangci-lint linters

Test Configuration Locally

golangci-lint run --config .golangci.yml