leakcheck

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

README

leakcheck - Goroutine Leak Detection Linter

GitHub Actions Workflow Status Codecov GitHub License

A static analysis tool that ensures all Go test functions are properly covered by goleak for goroutine leak detection.

Features

  • Detects missing goleak imports and defer goleak.VerifyNone(t) calls in test functions
  • Validates TestMain(m *testing.M) with goleak.VerifyTestMain(m) setup
  • Supports package aliases and configurable exclusion patterns

Quick Start

# Install
go install github.com/rleungx/leakcheck/cmd/leakcheck@latest

# Usage
leakcheck ./...                                    # Analyze all packages
leakcheck -exclude-files="*mock*" ./...           # Exclude files
leakcheck -exclude-packages="vendor" ./...        # Exclude packages
leakcheck -h                                       # Show help

Examples

Missing goleak Import
// ❌ Will be flagged
func TestSomething(t *testing.T) {
    // goleak not imported
}
Missing defer Statement
import "go.uber.org/goleak"

// ❌ Missing defer
func TestSomething(t *testing.T) {
    // test logic
}

// ✅ Correct
func TestCorrect(t *testing.T) {
    defer goleak.VerifyNone(t)
    // test logic
}
TestMain Coverage
// ❌ TestMain without goleak
func TestMain(m *testing.M) {
    os.Exit(m.Run())
}

// ✅ Correct - covers all tests
func TestMain(m *testing.M) {
    goleak.VerifyTestMain(m)
}

Development

git clone https://github.com/rleungx/leakcheck.git
cd leakcheck

# Build
make build

# Run tests
make test

# Run tests with coverage
make test-coverage

# Run linter
make lint

# Tidy dependencies
make tidy

License

Apache License 2.0 - see LICENSE file for details.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Analyzer = New()

Analyzer is the default analyzer instance for backward compatibility

Functions

func New

func New() *analysis.Analyzer

New creates a new leakcheck analyzer with default configuration

func NewWithConfig

func NewWithConfig(config *Config) *analysis.Analyzer

NewWithConfig creates a new leakcheck analyzer with custom configuration

Types

type Config

type Config struct {
	ExcludePackages string
	ExcludeFiles    string
}

Config holds the configuration for the leakcheck analyzer

Directories

Path Synopsis
cmd
leakcheck command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL