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
{{ message }}
Repository navigation
lenstringzero coverage gap: len(s) != 0 is flagged but the identical idiom len(s) > 0 (and len(s) < 1 / <= 0) escapes — relation
[Content truncated due to length] #40581
pkg/linters/lenstringzero flags len(s) == 0 → s == "" and len(s) != 0 → s != "", but it only matches the equality operators (token.EQL / token.NEQ). The exactly-equivalent relational forms on strings escape:
Written
Equivalent to
Flagged today?
len(s) == 0
s == "" (empty)
✅ yes
len(s) != 0
s != "" (non-empty)
✅ yes
len(s) > 0
s != "" (non-empty)
❌ no
len(s) < 1 / len(s) <= 0
s == "" (empty)
❌ no
len(s) >= 1
s != "" (non-empty)
❌ no
Since len(s) >= 0 always holds for strings, len(s) > 0 and len(s) != 0 are semantically identical — yet only one is reported. That inconsistency is the gap.
len(s) > 0 is the most common non-empty idiom in Go, so this is the larger of the two cases by prevalence. Real string-typed sites exist in production, e.g.:
pkg/stringutil/stringutil.go:44 — if len(normalized) > 0 {
pkg/stringutil/sanitize.go:209 — if len(result) > 0 && ...
(The narrow scoping is plausibly intentional precisely because> 0 is so prevalent — see the tradeoff below.)
Recommendation (team to decide scope)
The equivalence is exact, so extending coverage is consistent with the linter's stated goal (prefer direct string comparison). Two viable directions:
Extend the operator set to the relational forms, mapping to the correct empty/non-empty fixer:
reuse the existing literal-zero / yoda-swap and string-type guard (lenStringArg), and adjust cmpVerb + the suggested-fix operator accordingly.
Document the boundary explicitly in the analyzer Doc and doc.go if > 0 is deliberately excluded as too noisy — so the asymmetry is an intentional, recorded decision rather than an apparent oversight.
This report favors a deliberate choice over the current silent asymmetry where != 0 is flagged but the identical > 0 is not.
Validation checklist
If extending: testdata len(s) > 0 → diagnostic + fix s != ""; len(s) < 1 → fix s == ""; yoda 0 < len(s) handled.
Non-string len(slice) > 0 still not flagged (the *types.Basic String guard already covers this).
len(s) >= 0 (always-true) and len(s) < 0 (always-false) are not mis-fixed.
go test ./pkg/linters/lenstringzero/... passes.
Effort
Small–medium — single file; the type guard, alias tracking, and yoda handling already exist and are reusable; main work is operator mapping + fixer text + testdata.
Not a duplicate of any open sergo issue (no existing lenstringzero issue).
The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: 1828:980C1:17C492A:571CD4B:6A377BDA)
Activity
github-actions commentedon Jun 21, 2026
🍪 Issue Monster selected this for Copilot
I've identified this issue as a good candidate for automated resolution and requested assignment to the Copilot coding agent.
If assignment succeeds, the Copilot coding agent will analyze the issue and create a pull request with the fix.
Om nom nom! 🍪
Copilot commentedon Jun 21, 2026
The agent encountered an error and was unable to start working on this issue: Please try again later, or contact support if the problem persists. (Request id: 1828:980C1:17C492A:571CD4B:6A377BDA)
feat(lenstringzero): extend linter to flag relational len comparisons…
github-actions commentedon Jun 28, 2026
This issue was automatically closed because it expired on 2026-06-28T05:30:56.009Z.