Closed
linters: add bytescomparezero analyzer for bytes.Compare(... ) == 0 equality checks#48500
bytescomparezero analyzer for bytes.Compare(... ) == 0 equality checks#48500Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add bytescomparezero linter for equality checks
linters: add Jul 28, 2026
bytescomparezero analyzer for bytes.Compare(... ) == 0 equality checks
pelikhan
marked this pull request as ready for review
July 28, 2026 03:38
Contributor
There was a problem hiding this comment.
Pull request overview
Adds and registers the bytescomparezero Go analyzer to replace equality-oriented bytes.Compare checks with idiomatic bytes.Equal.
Changes:
- Implements detection, suppression, generated-file skipping, and suggested fixes.
- Adds analyzer fixtures and documentation/registry synchronization.
- Refreshes generated workflow metadata.
Show a summary per file
| File | Description |
|---|---|
pkg/linters/bytescomparezero/bytescomparezero.go |
Implements the analyzer and fixes. |
pkg/linters/bytescomparezero/bytescomparezero_test.go |
Runs analyzer fixture tests. |
pkg/linters/bytescomparezero/testdata/src/bytescomparezero/bytescomparezero.go |
Adds primary test cases. |
pkg/linters/bytescomparezero/testdata/src/bytescomparezero/bytescomparezero.go.golden |
Defines expected rewrites. |
pkg/linters/bytescomparezero/testdata/src/bytescomparezero/aliased_import.go |
Tests aliased imports. |
pkg/linters/bytescomparezero/testdata/src/bytescomparezero/aliased_import.go.golden |
Defines alias-preserving rewrites. |
pkg/linters/bytescomparezero/testdata/src/bytescomparezero/generated.go |
Verifies generated files are skipped. |
pkg/linters/registry.go |
Registers the analyzer. |
pkg/linters/spec_test.go |
Adds it to documented analyzer checks. |
pkg/linters/doc.go |
Documents the analyzer and updates the count. |
pkg/linters/README.md |
Adds public package documentation. |
.github/workflows/smoke-copilot-auto.lock.yml |
Adds generated model-cost metadata. |
Review details
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Files not reviewed (1)
- pkg/linters/bytescomparezero/testdata/src/bytescomparezero/generated.go: Generated file
- Files reviewed: 11/12 changed files
- Comments generated: 1
- Review effort level: Medium
Comment on lines
+93
to
+95
| Pos: expr.Pos(), | ||
| End: expr.End(), | ||
| NewText: []byte(replacement), |
Collaborator
|
@copilot resolve the merge conflicts on this branch. |
Copilot stopped work on behalf of
pelikhan due to an error
July 28, 2026 03:44
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.
Adds a new custom Go analyzer,
bytescomparezero, to catch equality-stylebytes.Compareusage and suggest the idiomaticbytes.Equalform. This closes a readability/intent gap while preserving non-equality compare semantics.Analyzer implementation (
pkg/linters/bytescomparezero)bytes.Compare(a, b) == 0bytes.Compare(a, b) != 00 == bytes.Compare(a, b)(yoda form)0 != bytes.Compare(a, b)(yoda form)bytes.Equal(a, b)!bytes.Equal(a, b)< 0,> 0,== 1, etc.).//nolint:bytescomparezeroand skips generated files.bx.Compare->bx.Equal).Registration and docs sync
bytescomparezeroinpkg/linters/registry.go.pkg/linters/doc.go(analyzer list/count)pkg/linters/README.md(subpackage + overview entries)pkg/linters/spec_test.go(documented analyzer set)Linter fixtures
analysistestcases and goldens covering normal, yoda, alias, nolint, and generated-file scenarios.