Add errstklint: Linter to enforce defer errstk.Wrap(&err)#2
Merged
Conversation
This commit adds a comprehensive linter tool to ensure all functions returning errors include defer errstk.Wrap(&err) for proper stack trace capture. Features: - Standalone CLI tool (cmd/errstklint) - golangci-lint plugin support (errstklint/) - File exclusion patterns using glob (e.g., generated/*.go, **/mock_*.go) - Configurable via CLI flags or .golangci.yml Implementation: - errstklint/: Public package with analyzer and plugin support - analyzer.go: Core analysis logic using go/analysis framework - plugin.go: golangci-lint plugin integration with config parsing - Supports exclude patterns via -exclude flag or YAML config - cmd/errstklint/: Standalone CLI tool - Uses errstklint package as library - Independent go.mod for separate dependency management - Comprehensive test suite with testdata - Updated CI workflow to test all components Usage: # Standalone errstklint -exclude="generated/*.go,**/mock_*.go" ./... # golangci-lint plugin # .golangci.yml: # linters-settings: # errstklint: # exclude: # - "generated/*.go" 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Changes: - Remove cmd/errstklint/go.mod and errstklint/go.mod - Merge all dependencies into root go.mod - Move analyzer_test.go and testdata to errstklint/ package - Keep cmd/errstklint/ as CLI entry point only Benefits: - Simpler module structure (single go.mod) - go install github.com/tomoemon/go-errstk/cmd/errstklint@version works - Library users don't get linter dependencies (unless they import it) - Tests are co-located with implementation
Changes: - Add linter to Design Philosophy in root README - Simplify cmd/errstklint/README.md (CLI-focused) - Expand errstklint/README.md with comprehensive docs - Fix golangci-lint config syntax (linters: settings:) - Add module structure explanation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add errstklint, a linter tool that ensures all functions returning errors include
defer errstk.Wrap(&err)for proper stack trace capture.Features
Standalone CLI Tool
go install github.com/tomoemon/go-errstk/cmd/errstklint@latest errstklint ./... errstklint -exclude="generated/*.go,**/mock_*.go" ./...golangci-lint Plugin Support
File Exclusion Patterns
**for directory recursiongenerated/*.go,**/mock_*.go,**/*_test.goImplementation
Single Module Structure
Dependency Isolation: Library users (
import "github.com/tomoemon/go-errstk") don't get linter dependencies. Only projects importingerrstklintpackage getgolang.org/x/toolsdependencies.Usage
Detects missing defer:
Testing
Test plan
go installworks correctly🤖 Generated with Claude Code