You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds a new custom Go analysis linter bytescomparezero that flags the common anti-pattern of using bytes.Compare purely for equality checks:
// flaggedbytes.Compare(a, b) ==0bytes.Compare(a, b) !=0// suggestedbytes.Equal(a, b)
!bytes.Equal(a, b)
Why
bytes.Equal directly expresses the intent of an equality check, is more readable, and avoids the cognitive overhead of remembering that bytes.Compare returns 0 for equal slices. This pattern is frequently introduced by developers used to strings.Compare or coming from other languages.
Evidence
Scanning the codebase and known Go idioms: bytes.Compare(...) == 0 is a well-known stylistic anti-pattern. The bytes.Equal function exists precisely for equality checks and is the idiomatic Go style per the standard library docs.
Implementation
New package: pkg/linters/bytescomparezero/
Analyzer name: bytescomparezero
Emits a SuggestedFix for automated rewriting
Handles 0 == bytes.Compare(a, b) (zero on left) too
Skips ordering comparisons (< 0, > 0, == 1, etc.)
Respects //nolint:bytescomparezero directives
Skips generated files
Registered in pkg/linters/registry.go and documented in pkg/linters/README.md
Test
go test ./pkg/linters/bytescomparezero/...
ok github.com/github/gh-aw/pkg/linters/bytescomparezero
Warning
Protected Files — Push Permission Denied
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.md
The push was rejected because GitHub Actions does not have workflows permission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.
Create the pull request manually
# Download the patch from the workflow run
gh run download 30291438401 -n agent -D /tmp/agent-30291438401
# Create a new branch
git checkout -b linter-miner/bytescomparezero-a93111e951294b3e main
# Apply the patch (--3way handles cross-repo patches)
git am --3way /tmp/agent-30291438401/aw-linter-miner-bytescomparezero.patch
# Push the branch and create the pull request
git push origin linter-miner/bytescomparezero-a93111e951294b3e
gh pr create --title '[linter-miner] linters: add bytescomparezero linter' --base main --head linter-miner/bytescomparezero-a93111e951294b3e --repo github/gh-aw
Summary
Adds a new custom Go analysis linter
bytescomparezerothat flags the common anti-pattern of usingbytes.Comparepurely for equality checks:Why
bytes.Equaldirectly expresses the intent of an equality check, is more readable, and avoids the cognitive overhead of remembering thatbytes.Comparereturns 0 for equal slices. This pattern is frequently introduced by developers used tostrings.Compareor coming from other languages.Evidence
Scanning the codebase and known Go idioms:
bytes.Compare(...) == 0is a well-known stylistic anti-pattern. Thebytes.Equalfunction exists precisely for equality checks and is the idiomatic Go style per the standard library docs.Implementation
pkg/linters/bytescomparezero/bytescomparezeroSuggestedFixfor automated rewriting0 == bytes.Compare(a, b)(zero on left) too< 0,> 0,== 1, etc.)//nolint:bytescomparezerodirectivespkg/linters/registry.goand documented inpkg/linters/README.mdTest
Warning
Protected Files — Push Permission Denied
This was originally intended as a pull request, but the patch modifies protected files. A human must create the pull request manually.
Protected files
README.mdThe push was rejected because GitHub Actions does not have
workflowspermission to push these changes, and is never allowed to make such changes, or other authorization being used does not have this permission.Create the pull request manually