This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
zerologlintctx is a Go linter that enforces context propagation in zerolog logging chains. It detects:
- Event chains missing
.Ctx(ctx)when context is available - Direct logging calls (
Print,Printf,Println) that bypass the Event chain
See Architecture for internal design details.
# Run ALL tests (ALWAYS use this before committing)
./test_all.sh
# Run tests
go test ./...
# Run tests with verbose output
go test -v ./...
# Build CLI
go build -o bin/zerologlintctx ./cmd/zerologlintctx
# Run linter on itself
go vet -vettool=./bin/zerologlintctx ./...
# Run golangci-lint
golangci-lint run ./...Important
Always use ./test_all.sh before committing. This runs all tests including linting.
- Use
analysistestfor all analyzer tests - Test fixtures use
// wantcomments for expected diagnostics - Test structure:
===== SHOULD REPORT =====- Cases that should trigger warnings===== SHOULD NOT REPORT =====- Negative cases===== EDGE CASES =====- Corner cases
testdata/src/zerolog/
├── basic.go # Simple good/bad cases, ignore directives
├── evil.go # General edge cases (nesting, closures, conditionals)
├── evil_ssa.go # SSA-specific patterns (IIFE, Phi, channels)
├── evil_logger.go # Logger transformation patterns, direct logging
└── with_logger.go # WithLogger-specific tests
- Follow standard Go conventions
- Use
go/analysisframework - Prefer type-based checks over name-based (see Architecture)
- Unexported types by default; only export what's needed
Comments should inform newcomers, not document history.
- Bad:
// moved from evil.go - Bad:
// refactored in session 5 - Good:
// LIMITATION: cross-function tracking not supported
- Type-safe analysis: Uses return types (
returnsEvent,returnsLogger, etc.) instead of method name hardcoding - SSA tracing: Strategy Pattern with three tracers (Event, Logger, Context)
- Zero false positives: Prefer missing issues over false alarms
- Helper function returns: Can't track through interprocedural analysis (IIFE is supported)
- Channel send/receive: Can't trace through channels
- Closure-modified capture: Closure writes to outer variable
These are documented in test cases with // LIMITATION comments.
- README.md - User documentation
- Architecture - Internal design and detection logic