Skip to content

fix: use strings.Cut to resolve stringscut lint violation in known_needs_expressions#17728

Merged
pelikhan merged 2 commits intomainfrom
copilot/fix-lint-go-stringscut-error
Feb 22, 2026
Merged

fix: use strings.Cut to resolve stringscut lint violation in known_needs_expressions#17728
pelikhan merged 2 commits intomainfrom
copilot/fix-lint-go-stringscut-error

Conversation

Copy link
Contributor

Copilot AI commented Feb 22, 2026

golangci-lint was failing CI with stringscut: strings.Index can be simplified using strings.Cut in pkg/workflow/known_needs_expressions.go:145.

Change

Replaced the strings.Index + manual slice pattern with the idiomatic strings.Cut:

// Before
dotIdx := strings.Index(rest, ".")
if dotIdx < 0 { ... }
jobName := rest[:dotIdx]

// After
jobName, _, ok := strings.Cut(rest, ".")
if !ok { ... }
Original prompt

This section details on the original issue you should resolve

<issue_title>[CI Failure Doctor] Investigate lint-go stringscut failure</issue_title>
<issue_description>### CI Failure Investigation - Run github/gh-aw#37390

Summary

golangci-lint failed in the lint-go job because pkg/workflow/known_needs_expressions.go still splits a needs.* expression with strings.Index, which triggers the modernize stringscut rule.

Failure Details

Root Cause Analysis

The lint-go job runs make golint, which invokes golangci-lint with the modernize suite that includes the stringscut check. The log shows pkg/workflow/known_needs_expressions.go:145:13: stringscut: strings.Index can be simplified using strings.Cut, so the linter exits with code 2 before any other checks run.

Failed Jobs and Errors

  • lint-gopkg/workflow/known_needs_expressions.go:145:13: stringscut: strings.Index can be simplified using strings.Cut (modernize)
Investigation Findings
  • Running make golint locally reproduces the failure because the stringscut rule is enabled by default in the lint configuration.
  • Swapping the strings.Index call for strings.Cut eliminates the warning without affecting the existing logic that drops post-activation needs expressions.
  • Attempts to run make fmt on the tree fail because go fmt ./... wants Go 1.25.0 but the download from proxy.golang.org is blocked, and forcing GOTOOLCHAIN=local runs against Go 1.24.12, which is below the module's go 1.25 requirement.

Recommended Actions

  • Re-run make golint on main after merging this change to confirm no other stringscut violations remain.

Prevention Strategies

Use strings.Cut (or other modern splitting helpers) whenever slicing needs.* expressions so the stringscut lint rule stays satisfied across the codebase.

AI Team Self-Improvement

Always prefer the Go 1.21+ helpers (e.g., strings.Cut) for substring extraction so modernization rules like stringscut do not break CI.

Historical Context

No prior CI Failure Doctor investigations matched this stringscut violation pattern.

🩺 Diagnosis provided by CI Failure Doctor

To install this workflow, run gh aw add githubnext/agentics/workflows/ci-doctor.md@ea350161ad5dcc9624cf510f134c6a9e39a6f94d. View source at https://github.com/githubnext/agentics/tree/ea350161ad5dcc9624cf510f134c6a9e39a6f94d/workflows/ci-doctor.md.

  • expires on Feb 23, 2026, 1:48 PM UTC

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

…olation

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate and fix lint-go stringscut failure fix: use strings.Cut to resolve stringscut lint violation in known_needs_expressions Feb 22, 2026
@pelikhan pelikhan marked this pull request as ready for review February 22, 2026 14:11
Copilot AI review requested due to automatic review settings February 22, 2026 14:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates known_needs_expressions parsing to satisfy golangci-lint’s modernize(stringscut) rule by replacing a strings.Index + slicing pattern with strings.Cut, preserving the existing behavior for malformed needs.* expressions.

Changes:

  • Replace strings.Index(rest, ".") + manual slicing with strings.Cut(rest, ".") in filterExpressionsForActivation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@pelikhan pelikhan merged commit 18ff0b0 into main Feb 22, 2026
120 checks passed
@pelikhan pelikhan deleted the copilot/fix-lint-go-stringscut-error branch February 22, 2026 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI Failure Doctor] Investigate lint-go stringscut failure

3 participants