Skip to content

chore: fix golangci-lint findings (dead code, ineffassign, staticcheck)#527

Merged
kevincodex1 merged 1 commit into
Gitlawb:mainfrom
euxaristia:fix/lint-cleanup-main
Jul 6, 2026
Merged

chore: fix golangci-lint findings (dead code, ineffassign, staticcheck)#527
kevincodex1 merged 1 commit into
Gitlawb:mainfrom
euxaristia:fix/lint-cleanup-main

Conversation

@euxaristia

@euxaristia euxaristia commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Small cleanup pass from running golangci-lint locally (installed it after CodeRabbit's truncateHeadTail nitpick on #476 turned out to have no equivalent check in this repo's actual CI, which only runs go vet).

Changes

  • Remove three unused functions found by the unused linter: safeRequestedPrefix, safeShellCommandTokens (internal/agent/command_prefix.go), and truncateHeadTail (internal/tools/bash.go). Each was a thin wrapper with no remaining callers.
  • Drop an ineffectual assignment in stringListArgWebSearch (internal/tools/web_search.go): every return path after it already sets the named return explicitly, so the assignment never took effect.
  • Simplify a negated-and condition in partition_cache_stable_test.go via De Morgan's law.
  • Use strings.Contains instead of strings.Index(...) < 0 in edit_replacers.go.
  • Fix error string style (staticcheck ST1005): lowercase "unsafe redirect URL" and drop the trailing period from webFetchPublicOnlyHint in web_fetch.go, updating the one test that asserted on the old casing.

Deliberately left the errcheck findings (unchecked defer file.Close() / response.Body.Close() / Write() errors) alone. Those are stylistic, not correctness bugs, and this repo's CI doesn't run golangci-lint at all, so there's no actual gate to satisfy there.

Test plan

  • go build ./...
  • go vet ./... (clean, matches actual CI)
  • go test ./internal/agent/... ./internal/tools/... (pass)
  • golangci-lint run ./internal/agent/... ./internal/tools/... --enable-only unused,ineffassign,staticcheck (0 issues, down from 6)

Summary by CodeRabbit

  • Bug Fixes

    • Improved the wording and consistency of a few error messages shown during unsafe redirect handling and web fetch prompts.
    • Tightened validation and matching behavior in some command and edit workflows for more reliable results.
  • Refactor

    • Simplified several internal code paths and cleanup logic without changing expected user-facing behavior.
    • Updated test assertions to better reflect the current output format.

- Remove unused safeRequestedPrefix, safeShellCommandTokens
  (internal/agent/command_prefix.go), and truncateHeadTail
  (internal/tools/bash.go): each was a thin wrapper with no remaining
  callers.
- Drop an ineffectual assignment in stringListArgWebSearch: every
  return path after it already sets the named return explicitly.
- Simplify a negated-and condition in
  partition_cache_stable_test.go via De Morgan's law.
- Use strings.Contains instead of strings.Index(...) < 0 in
  edit_replacers.go.
- Fix error string style (ST1005): lowercase "unsafe redirect URL"
  and drop the trailing period from webFetchPublicOnlyHint.

Skipped the errcheck findings on this pass (unchecked defer
Close()/Write() errors): those are stylistic, not correctness bugs,
and this repo's CI only runs go vet, not golangci-lint.
@coderabbitai

coderabbitai Bot commented Jul 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a7753e38-d345-471c-aa32-e799c5a9b48e

📥 Commits

Reviewing files that changed from the base of the PR and between 95ccd5b and 14f60dc.

📒 Files selected for processing (7)
  • internal/agent/command_prefix.go
  • internal/agent/partition_cache_stable_test.go
  • internal/tools/bash.go
  • internal/tools/edit_replacers.go
  • internal/tools/web_fetch.go
  • internal/tools/web_fetch_test.go
  • internal/tools/web_search.go
💤 Files with no reviewable changes (3)
  • internal/tools/web_search.go
  • internal/agent/command_prefix.go
  • internal/tools/bash.go

Walkthrough

This PR removes unused helper functions (safeRequestedPrefix, safeShellCommandTokens, truncateHeadTail), simplifies a test conditional and a fuzzy-match check, adjusts message casing/punctuation in web_fetch.go with corresponding test updates, and removes a redundant assignment in web_search.go.

Changes

Cleanup and minor fixes

Layer / File(s) Summary
Remove unused command-prefix helpers
internal/agent/command_prefix.go
Deletes the unused safeRequestedPrefix and safeShellCommandTokens internal helper functions.
Simplify cache ordering test assertion
internal/agent/partition_cache_stable_test.go
Rewrites a negated compound condition into direct >= comparisons for verifying tool ordering.
Remove unused truncateHeadTail helper
internal/tools/bash.go
Deletes truncateHeadTail, leaving truncateHeadTailWithTotal as the sole truncation implementation.
Simplify fuzzy edit candidate check
internal/tools/edit_replacers.go
Replaces strings.Index(...) < 0 with !strings.Contains(...) for equivalent candidate validation.
Adjust web fetch message casing/punctuation
internal/tools/web_fetch.go, internal/tools/web_fetch_test.go
Removes trailing period from a hint string and lowercases "unsafe redirect URL" in the error message, updating the test assertion accordingly.
Simplify provided flag handling
internal/tools/web_search.go
Removes a redundant standalone provided = true assignment, relying on later explicit returns.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

  • Gitlawb/zero#218: Both PRs modify the domains argument parsing/validation logic in stringListArgWebSearch.
  • Gitlawb/zero#322: Related to the same command-prefix helper removal tied to a segment-based prefix refactor.
  • Gitlawb/zero#506: Both PRs touch fuzzyEditMatch's candidate validation logic in edit_replacers.go.

Suggested reviewers: gnanam1990, anandh8x, Vasanthdev2004

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the cleanup pass fixing golangci-lint findings across dead code, ineffassign, and staticcheck issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@Vasanthdev2004

Findings

  • [P2] Tie this cleanup to an approved parent issue or maintainer-approved scope
    CONTRIBUTING.md:45
    This PR is from a CONTRIBUTOR account and does not link an approved parent issue, but the project contribution policy says all community PRs require an approved parent issue with the issue-approved label before implementation starts. The change is also a cleanup/refactor pass driven by local golangci-lint output rather than a linked approved bug or feature, which falls under the same scope rule. Please link the approved issue for this cleanup, or get explicit maintainer approval for taking this contributor cleanup outside the issue-first flow.

kevincodex1 pushed a commit that referenced this pull request Jul 6, 2026
go vet, gofmt, govulncheck, and deadcode don't catch unused private
functions/assignments reachable within a package but never called, or
staticcheck-style correctness/readability issues. deadcode's whole-program
reachability analysis specifically missed several of these; golangci-lint's
truncateHeadTail nitpick on #476 assumed it would fail CI, but nothing in
this repo actually ran it.

Scoped to unused, ineffassign, and staticcheck rather than the full default
battery, and continue-on-error like deadcode, so this surfaces the existing
findings across the repo (being cleaned up incrementally per #527) without
blocking in-flight PRs on a big-bang adoption.

@kevincodex1 kevincodex1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@kevincodex1 kevincodex1 merged commit 8c6c49a into Gitlawb:main Jul 6, 2026
7 checks passed
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.

3 participants