feat: Add -fix flag support for auto-correction#7
Merged
Conversation
Enable automatic fixing of missing defer errstk.Wrap(&err) via the -fix flag (standalone) or --fix (golangci-lint). The auto-fix handles: - Unnamed return values converted to named returns (error→err, others→_) - defer errstk.Wrap(&err) inserted at function body start - errstk import added if not present Functions with multiple error return values are not auto-fixed and show a warning message instead. Also adds sample golangci-lint configuration files and updates READMEs. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
-fixフラグ(スタンドアロン)および--fix(golangci-lint)による自動修正をサポートerror→err error、その他 →_ type)し、defer errstk.Wrap(&err)を関数本体の先頭に挿入、必要に応じてimportも追加error返り値を持つ関数は自動修正対象外とし、警告メッセージを表示.custom-gcl.example.yml,.golangci.example.yml)を追加Test plan
go test ./errstklint/ -vで既存テスト・新規テスト全て通ることTestAnalyzerWithSuggestedFixesで Case A〜D(名前付き返り値、名前なし単一、名前なし複数、複数error)の自動修正が期待通り動作すること.goldenファイルとの一致を確認errstklint -fix ./...でスタンドアロン実行時の自動修正を動作確認🤖 Generated with Claude Code