Skip to content

stringsindexhasprefix: real production violation in frontmatter_on_section_cleanup.go — strings.Index(...) == 0 should be string [Content truncated due to length] #49267

Description

@github-actions

Summary

pkg/linters/stringsindexhasprefix (a non-enforced analyzer, not yet in LINTER_FLAGS) has exactly one true-positive violation in production code, at pkg/workflow/frontmatter_on_section_cleanup.go:705:

if idx := strings.Index(trimmedLine, "workflow_run:"); idx == 0 {

This is precisely the pattern the analyzer targets: strings.Index(s, sub) == 0 is equivalent to, and less clear than, strings.HasPrefix(s, sub). The comparison result idx is also unused past the == 0 check (the idx := binding only exists to feed the comparison), so the fix also removes a small amount of indirection.

Evidence

Grep of all strings.Index(...) call sites in pkg/ (non-test) compared against literal 0 found exactly this one instance; every other production strings.Index use compares against a non-zero-implying pattern or checks for -1/>= 0 (substring existence, not prefix position), which stringsindexhasprefix correctly does not flag.

Recommendation

  1. Fix pkg/workflow/frontmatter_on_section_cleanup.go:705:
    if strings.HasPrefix(trimmedLine, "workflow_run:") {
    (drop the now-unused idx binding)
  2. Once fixed, stringsindexhasprefix has zero remaining production violations — add -stringsindexhasprefix to the CI LINTER_FLAGS in .github/workflows/cgo.yml (both the default and wasm gates), same pattern as the recent stringsindexcontains/stringscountcontains enforce-readiness rollouts.

Validation checklist

  • Apply the one-line fix and confirm go build/existing tests for frontmatter_on_section_cleanup.go still pass
  • Run make golint-custom LINTER_FLAGS="-stringsindexhasprefix -test=false" and confirm zero remaining findings
  • Add -stringsindexhasprefix to both cgo.yml LINTER_FLAGS invocations

Effort

Trivial — one-line semantic-preserving rewrite plus a CI flag addition.

Generated by 🤖 Sergo - Serena Go Expert · agent · 250.3 AIC · ⌖ 6.22 AIC · ⊞ 6K ·

  • expires on Aug 6, 2026, 9:04 PM UTC-08:00

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!sergo

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions