Skip to content

build(golangci-lint): require guard clauses instead of else after return - #11

Merged
furedea merged 1 commit into
mainfrom
build/require-guard-clauses
Nov 15, 2026
Merged

furedea merged 1 commit into
mainfrom
build/require-guard-clauses

Conversation

@furedea-agent

@furedea-agent furedea-agent Bot commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

概要

.golangci.yml の revive ルールに indent-error-flow,superfluous-else,early-return を追加しました.return / continue / break で終わる if ブロックの後ろに else を置くコードを,文章ルールではなくリンターで拒否します.

変更前後の例

変更前(リンターを通過する):

func sample(x int) int {
	if x > 0 {
		return 1
	} else {
		return 2
	}
}

変更後(indent-error-flow が報告する):

zz_example.go:6:9: indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)

ガード節に書き直すと通ります:

func sample(x int) int {
	if x > 0 {
		return 1
	}
	return 2
}

検証

ピン留めされた golangci-lint 2.14.0(nix develop 経由)で確認しました.

  • 3 つのルール名はいずれも revive に存在し,設定エラーなく受理された
  • 上記の使い捨てサンプルが indent-error-flow で報告されることを確認し,サンプルは削除済み(コミットしていない)
  • golangci-lint run: 0 issues
  • go test ./...: pass
  • go vet ./...: 指摘なし
  • テンプレート側のコードに新しい指摘はなく、修正は不要

補足

使い捨てサンプルでは superfluous-else と early-return 固有の報告は出ていません(indent-error-flow が先に同じ構造を報告したため).両ルールが設定として有効であることは,設定エラーが出ないことで確認しています.

🤖 Generated with Claude Code

Enable the revive rules indent-error-flow, superfluous-else and
early-return so the linter rejects an else branch after an if block
that ends with return, continue or break.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@furedea

furedea commented Nov 15, 2026

Copy link
Copy Markdown
Owner

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 15, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-15T05:17:20.410272Z 0a18051 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown

Review summary: No findings. This PR only changes config: it adds the revive rules indent-error-flow, superfluous-else and early-return to .golangci.yml. All three are valid revive rule names. They sit in the explicit rules list next to the existing rules, so they are enabled without changing how the other rules are configured. I found no correctness or security problems, and lint config changes don't need tests.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 0a18051533

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@furedea
furedea merged commit 6ef4e83 into main Nov 15, 2026
18 checks passed
@furedea
furedea deleted the build/require-guard-clauses branch November 15, 2026 10:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant