Repository navigation
empty-block: skip bare for-range loops - #1710
Merged
alexandear merged 3 commits intoApr 24, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adjusts the empty-block rule to avoid reporting empty bodies for bare for range loops, addressing false positives for common channel-draining patterns (issue #386).
Changes:
- Update
empty-blockrule logic to skip emptyRangeStmtbodies when both key and value are omitted. - Update
testdata/empty_block.gofixtures to reflect the new behavior and add a helper returning a closed channel.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| rule/empty_block.go | Skips reporting empty blocks for bare for range statements. |
| testdata/empty_block.go | Updates fixtures for the new for range behavior and adds makeChan() helper. |
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the empty-block rule to avoid false positives on intentionally empty bare for range loops (commonly used for channel draining), and aligns fixtures/docs with the new behavior.
Changes:
- Skip reporting for empty
for range <expr> {}loops when both key and value are omitted. - Update
testdata/empty_block.goto add coverage for range variants and to reflect the new βmust not matchβ expectations. - Update
RULES_DESCRIPTIONS.mdto document the newly skipped patterns and the resulting false-negative tradeoff.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
rule/empty_block.go |
Adds a bare RangeStmt exemption to prevent warnings on common channel-draining patterns. |
testdata/empty_block.go |
Adjusts fixtures to validate the new exemption and keep a flagged non-bare range case. |
RULES_DESCRIPTIONS.md |
Documents the exemption behavior and limitations/false negatives. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
chavacava
approved these changes
Apr 24, 2026
Closed
merlimat
added a commit
to oxia-db/oxia
that referenced
this pull request
Oct 9, 2026
### Problem Since Go 1.27.2 was released, the `Build & Test` job fails at the `golangci-lint` step on every PR. Then the `Test` step is skipped, so CI runs no tests on PRs. `actions/setup-go` reads `go 1.27` from `go.work` and installs the latest 1.27.x. The Go 1.27.2 compiler writes export data in a new format version, 5. That's a backport of [go.dev/issue/81188](https://go.dev/issue/81188); 1.27.1 wrote version 4. golangci-lint v2.13.2 bundles `golang.org/x/tools` v0.49.0, which can only read up to version 4. So type-checking fails on the first standard library import of every package. ### Example 1. setup-go installs `go1.27.2 linux/amd64`. The last green run, [37688466181](https://github.com/oxia-db/oxia/actions/runs/37688466181/job/113022265427) on 2026-10-07, got `go1.27.1`. 2. `Install Go tools` builds golangci-lint v2.13.2. 3. `make lint` loads each package's dependencies from the export data that Go 1.27.2 writes, in version 5. x/tools v0.49.0 rejects it, and all five modules fail typecheck ([run 37805008553](https://github.com/oxia-db/oxia/actions/runs/37805008553/job/113957637137), PR #1281): ``` cmd/common/parse/map.go:18:2: could not import strings (/opt/hostedtoolcache/go/1.27.2/x64/src/strings/builder.go:8:2: could not import internal/abi (/opt/hostedtoolcache/go/1.27.2/x64/src/internal/abi/abi.go:8:2: could not import internal/goarch (-: could not load export data: internal error in importing "internal/goarch" (cannot decode "internal/goarch", export data version 5 is greater than maximum supported version 4); please report an issue))) (typecheck) ``` 4. `Check git status if clean` and `Test` are skipped. The same failure reproduces locally with `GOTOOLCHAIN=go1.27.2`. With this change, step 2 builds v2.14.0, whose x/tools v0.50.0 reads version 5, and step 3 reports `0 issues.` for every module. ### Change - `GOLANGCI_LINT_VERSION` goes from v2.13.2 to v2.14.0 in `ci-build-test.yaml` and `ci-release.yaml`. - v2.14.0 moves revive from v1.15.0 to v1.17.0. That changes three things here: - The new rules `multiline-if-init` and `marshal-receiver` flag 14 places in existing code. They're disabled in `.golangci.yaml`, the same way #1298 handled the rules added by the previous bump. - `empty-block` now skips bare `for range` loops (revive-lint/revive#1710), so the `//nolint:revive` on the channel drain in `notifications.Close` is no longer used. It's removed. Otherwise `fix: true` would delete it during `make lint`, and the clean-tree check would fail. - revive-lint/revive#1718 is fixed (revive-lint/revive#1719): an internal failure in one rule no longer stops the remaining rules for that file. #1309 disabled `inefficient-map-lookup` until this fix shipped, so the second commit turns it back on (0 findings). That commit can be dropped without affecting the rest. ### Testing Tested with golangci-lint v2.14.0 built with go1.27.2, a fresh `GOLANGCI_LINT_CACHE` and a private `TMPDIR` for each run: - The CI loop over all five go.work modules with `--fix=false` reports 0 issues under go1.27.2 and under go1.27.1. - Plain `make lint` (config `fix: true`) reports 0 issues and leaves the tree unchanged. - Flake check for `inefficient-map-lookup`: 30 runs of the full loop with the rule enabled had 0 failures. As a control, the same loop on `main` with only #1309 reverted, linted by v2.13.2 under go1.27.1, failed 3 out of 10 runs with the old symptom: needed `//nolint:revive` directives reported as unused. --------- Signed-off-by: Matteo Merli <mmerli@apache.org>
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.
Fixes #386 (comment)