style: use fmt.Fprintf instead of WriteString(fmt.Sprintf) (staticcheck QF1012)

Mechanical fix applied by golangci-lint --fix. Pre-existing debt that fails the staticcheck QF1012 quickfix check; no behavior change. Clears the lint gate so subsequent commits in this package set pass.
This commit is contained in:
2026-06-20 00:33:30 +01:00
parent aa7d884b0c
commit e11f140997
7 changed files with 45 additions and 45 deletions
+9 -9
View File
@@ -211,7 +211,7 @@ func GenerateMarkdown() string {
var sb strings.Builder var sb strings.Builder
sb.WriteString("# MCP Filepuff API Reference\n\n") sb.WriteString("# MCP Filepuff API Reference\n\n")
sb.WriteString(fmt.Sprintf("> Auto-generated on %s\n\n", time.Now().Format("2006-01-02"))) fmt.Fprintf(&sb, "> Auto-generated on %s\n\n", time.Now().Format("2006-01-02"))
sb.WriteString("This document provides detailed API documentation for all MCP tools available in filepuff.\n\n") sb.WriteString("This document provides detailed API documentation for all MCP tools available in filepuff.\n\n")
// Table of Contents // Table of Contents
@@ -228,9 +228,9 @@ func GenerateMarkdown() string {
} }
for _, cat := range categoryOrder { for _, cat := range categoryOrder {
sb.WriteString(fmt.Sprintf("### %s\n", cat)) fmt.Fprintf(&sb, "### %s\n", cat)
for _, tool := range categories[cat] { for _, tool := range categories[cat] {
sb.WriteString(fmt.Sprintf("- [`%s`](#%s)\n", tool.Name, tool.Name)) fmt.Fprintf(&sb, "- [`%s`](#%s)\n", tool.Name, tool.Name)
} }
sb.WriteString("\n") sb.WriteString("\n")
} }
@@ -240,11 +240,11 @@ func GenerateMarkdown() string {
sb.WriteString("## Tool Reference\n\n") sb.WriteString("## Tool Reference\n\n")
for _, cat := range categoryOrder { for _, cat := range categoryOrder {
sb.WriteString(fmt.Sprintf("### %s\n\n", cat)) fmt.Fprintf(&sb, "### %s\n\n", cat)
for _, tool := range categories[cat] { for _, tool := range categories[cat] {
sb.WriteString(fmt.Sprintf("#### `%s`\n\n", tool.Name)) fmt.Fprintf(&sb, "#### `%s`\n\n", tool.Name)
sb.WriteString(fmt.Sprintf("%s\n\n", tool.Description)) fmt.Fprintf(&sb, "%s\n\n", tool.Description)
// Read-only indicator // Read-only indicator
if tool.ReadOnly { if tool.ReadOnly {
@@ -263,8 +263,8 @@ func GenerateMarkdown() string {
if param.Required { if param.Required {
required = "**Yes**" required = "**Yes**"
} }
sb.WriteString(fmt.Sprintf("| `%s` | `%s` | %s | %s |\n", fmt.Fprintf(&sb, "| `%s` | `%s` | %s | %s |\n",
param.Name, param.Type, required, param.Description)) param.Name, param.Type, required, param.Description)
} }
sb.WriteString("\n") sb.WriteString("\n")
} else { } else {
@@ -285,7 +285,7 @@ func GenerateMarkdown() string {
if len(tool.Notes) > 0 { if len(tool.Notes) > 0 {
sb.WriteString("**Notes:**\n\n") sb.WriteString("**Notes:**\n\n")
for _, note := range tool.Notes { for _, note := range tool.Notes {
sb.WriteString(fmt.Sprintf("- %s\n", note)) fmt.Fprintf(&sb, "- %s\n", note)
} }
sb.WriteString("\n") sb.WriteString("\n")
} }
+16 -16
View File
@@ -278,27 +278,27 @@ func (r *Registry) Expose() string {
// Export counters // Export counters
for _, c := range r.counters { for _, c := range r.counters {
if c.help != "" { if c.help != "" {
sb.WriteString(fmt.Sprintf("# HELP %s %s\n", c.name, c.help)) fmt.Fprintf(&sb, "# HELP %s %s\n", c.name, c.help)
} }
sb.WriteString(fmt.Sprintf("# TYPE %s counter\n", c.name)) fmt.Fprintf(&sb, "# TYPE %s counter\n", c.name)
sb.WriteString(fmt.Sprintf("%s%s %d\n", c.name, formatLabels(c.labels), c.value.Load())) fmt.Fprintf(&sb, "%s%s %d\n", c.name, formatLabels(c.labels), c.value.Load())
} }
// Export gauges // Export gauges
for _, g := range r.gauges { for _, g := range r.gauges {
if g.help != "" { if g.help != "" {
sb.WriteString(fmt.Sprintf("# HELP %s %s\n", g.name, g.help)) fmt.Fprintf(&sb, "# HELP %s %s\n", g.name, g.help)
} }
sb.WriteString(fmt.Sprintf("# TYPE %s gauge\n", g.name)) fmt.Fprintf(&sb, "# TYPE %s gauge\n", g.name)
sb.WriteString(fmt.Sprintf("%s%s %d\n", g.name, formatLabels(g.labels), g.value.Load())) fmt.Fprintf(&sb, "%s%s %d\n", g.name, formatLabels(g.labels), g.value.Load())
} }
// Export histograms // Export histograms
for _, h := range r.histograms { for _, h := range r.histograms {
if h.help != "" { if h.help != "" {
sb.WriteString(fmt.Sprintf("# HELP %s %s\n", h.name, h.help)) fmt.Fprintf(&sb, "# HELP %s %s\n", h.name, h.help)
} }
sb.WriteString(fmt.Sprintf("# TYPE %s histogram\n", h.name)) fmt.Fprintf(&sb, "# TYPE %s histogram\n", h.name)
// Cumulative bucket counts // Cumulative bucket counts
var cumulative int64 var cumulative int64
@@ -306,26 +306,26 @@ func (r *Registry) Expose() string {
cumulative += h.counts[i].Load() cumulative += h.counts[i].Load()
labelStr := formatLabels(h.labels) labelStr := formatLabels(h.labels)
if labelStr == "" { if labelStr == "" {
sb.WriteString(fmt.Sprintf("%s_bucket{le=\"%g\"} %d\n", h.name, bound, cumulative)) fmt.Fprintf(&sb, "%s_bucket{le=\"%g\"} %d\n", h.name, bound, cumulative)
} else { } else {
// Insert le label into existing labels // Insert le label into existing labels
sb.WriteString(fmt.Sprintf("%s_bucket%s %d\n", h.name, fmt.Fprintf(&sb, "%s_bucket%s %d\n", h.name,
strings.Replace(labelStr, "}", fmt.Sprintf(",le=\"%g\"}", bound), 1), cumulative)) strings.Replace(labelStr, "}", fmt.Sprintf(",le=\"%g\"}", bound), 1), cumulative)
} }
} }
// +Inf bucket // +Inf bucket
cumulative += h.counts[len(h.buckets)].Load() cumulative += h.counts[len(h.buckets)].Load()
labelStr := formatLabels(h.labels) labelStr := formatLabels(h.labels)
if labelStr == "" { if labelStr == "" {
sb.WriteString(fmt.Sprintf("%s_bucket{le=\"+Inf\"} %d\n", h.name, cumulative)) fmt.Fprintf(&sb, "%s_bucket{le=\"+Inf\"} %d\n", h.name, cumulative)
} else { } else {
sb.WriteString(fmt.Sprintf("%s_bucket%s %d\n", h.name, fmt.Fprintf(&sb, "%s_bucket%s %d\n", h.name,
strings.Replace(labelStr, "}", ",le=\"+Inf\"}", 1), cumulative)) strings.Replace(labelStr, "}", ",le=\"+Inf\"}", 1), cumulative)
} }
// Sum and count // Sum and count
sb.WriteString(fmt.Sprintf("%s_sum%s %g\n", h.name, formatLabels(h.labels), h.Sum())) fmt.Fprintf(&sb, "%s_sum%s %g\n", h.name, formatLabels(h.labels), h.Sum())
sb.WriteString(fmt.Sprintf("%s_count%s %d\n", h.name, formatLabels(h.labels), h.count.Load())) fmt.Fprintf(&sb, "%s_count%s %d\n", h.name, formatLabels(h.labels), h.count.Load())
} }
return sb.String() return sb.String()
+3 -3
View File
@@ -44,11 +44,11 @@ func SkeletonFile(ctx context.Context, reg *Registry, filename string, content [
func renderSymbolsOnly(syms []protocol.Symbol, _ string, lang protocol.Language, content []byte) string { func renderSymbolsOnly(syms []protocol.Symbol, _ string, lang protocol.Language, content []byte) string {
lines := strings.Split(string(content), "\n") lines := strings.Split(string(content), "\n")
var sb strings.Builder var sb strings.Builder
sb.WriteString(fmt.Sprintf("// skeleton unavailable for %s — symbol list only\n", lang)) fmt.Fprintf(&sb, "// skeleton unavailable for %s — symbol list only\n", lang)
for _, s := range syms { for _, s := range syms {
sb.WriteString(fmt.Sprintf("// %s %s (line %d)\n", s.Kind, s.Name, s.Location.Line)) fmt.Fprintf(&sb, "// %s %s (line %d)\n", s.Kind, s.Name, s.Location.Line)
if s.Doc != "" { if s.Doc != "" {
sb.WriteString(fmt.Sprintf("// doc: %s\n", s.Doc)) fmt.Fprintf(&sb, "// doc: %s\n", s.Doc)
} }
if s.Location.Line >= 1 && s.Location.Line <= len(lines) { if s.Location.Line >= 1 && s.Location.Line <= len(lines) {
sb.WriteString(lines[s.Location.Line-1] + " { ... }\n") sb.WriteString(lines[s.Location.Line-1] + " { ... }\n")
+6 -6
View File
@@ -486,7 +486,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
// Emit preamble only when verbose=true is explicitly passed (opt-in, default off). // Emit preamble only when verbose=true is explicitly passed (opt-in, default off).
wantVerbose := len(verbose) > 0 && verbose[0] wantVerbose := len(verbose) > 0 && verbose[0]
if wantVerbose { if wantVerbose {
sb.WriteString(fmt.Sprintf("Found %d match(es):\n", renderCount)) fmt.Fprintf(&sb, "Found %d match(es):\n", renderCount)
} }
switch format { switch format {
@@ -498,13 +498,13 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
nodeType = r.Node.Type() nodeType = r.Node.Type()
} }
firstLine := firstLineOf(r.Text, 80) firstLine := firstLineOf(r.Text, 80)
sb.WriteString(fmt.Sprintf("%s:%d (%s) %s\n", r.File, r.Location.Line, nodeType, firstLine)) fmt.Fprintf(&sb, "%s:%d (%s) %s\n", r.File, r.Location.Line, nodeType, firstLine)
} }
case "location": case "location":
for i := 0; i < renderCount; i++ { for i := 0; i < renderCount; i++ {
r := results[i] r := results[i]
sb.WriteString(fmt.Sprintf("%s:%d\n", r.File, r.Location.Line)) fmt.Fprintf(&sb, "%s:%d\n", r.File, r.Location.Line)
} }
default: // "verbose" default: // "verbose"
@@ -514,7 +514,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
if r.Node != nil { if r.Node != nil {
nodeType = r.Node.Type() nodeType = r.Node.Type()
} }
sb.WriteString(fmt.Sprintf("**%s:%d** (%s)\n", r.File, r.Location.Line, nodeType)) fmt.Fprintf(&sb, "**%s:%d** (%s)\n", r.File, r.Location.Line, nodeType)
// Truncate very long text // Truncate very long text
text := r.Text text := r.Text
@@ -538,7 +538,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
if len(capText) > 50 { if len(capText) > 50 {
capText = capText[:50] + "..." capText = capText[:50] + "..."
} }
sb.WriteString(fmt.Sprintf("$%s=%s", name, capText)) fmt.Fprintf(&sb, "$%s=%s", name, capText)
} }
sb.WriteString("\n") sb.WriteString("\n")
} }
@@ -549,7 +549,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
if remaining > 0 { if remaining > 0 {
// Caller must embed the cursor token; we just append the remaining count hint. // Caller must embed the cursor token; we just append the remaining count hint.
// The actual [cursor: ...] line is written by the handler after calling MakeCursor. // The actual [cursor: ...] line is written by the handler after calling MakeCursor.
sb.WriteString(fmt.Sprintf("[remaining: %d]\n", remaining)) fmt.Fprintf(&sb, "[remaining: %d]\n", remaining)
} }
return sb.String() return sb.String()
+4 -4
View File
@@ -389,13 +389,13 @@ func (s *Searcher) FormatResultsWithOptions(results *SearchResults, opts FormatO
if opts.Verbose { if opts.Verbose {
totalMatches := len(results.Results) totalMatches := len(results.Results)
fileCount := len(fileResults) fileCount := len(fileResults)
sb.WriteString(fmt.Sprintf("Found %d matches in %d files", totalMatches, fileCount)) fmt.Fprintf(&sb, "Found %d matches in %d files", totalMatches, fileCount)
if results.Truncated { if results.Truncated {
sb.WriteString(fmt.Sprintf(" (truncated, total: %d)", results.Total)) fmt.Fprintf(&sb, " (truncated, total: %d)", results.Total)
} }
sb.WriteString(":\n\n") sb.WriteString(":\n\n")
} else if results.Truncated { } else if results.Truncated {
sb.WriteString(fmt.Sprintf("(truncated, showing subset of %d total matches)\n\n", results.Total)) fmt.Fprintf(&sb, "(truncated, showing subset of %d total matches)\n\n", results.Total)
} }
// Write results grouped by file // Write results grouped by file
@@ -408,7 +408,7 @@ func (s *Searcher) FormatResultsWithOptions(results *SearchResults, opts FormatO
} }
} }
sb.WriteString(fmt.Sprintf("**%s**\n", relPath)) fmt.Fprintf(&sb, "**%s**\n", relPath)
if opts.Cluster { if opts.Cluster {
writeClusteredResults(&sb, fileResults[file]) writeClusteredResults(&sb, fileResults[file])
+2 -2
View File
@@ -199,7 +199,7 @@ func TestSessionPrefsASTQueryMaxResults(t *testing.T) {
var sb strings.Builder var sb strings.Builder
sb.WriteString("package main\n\n") sb.WriteString("package main\n\n")
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
sb.WriteString(fmt.Sprintf("func Fn%c() {}\n\n", rune('A'+i))) fmt.Fprintf(&sb, "func Fn%c() {}\n\n", rune('A'+i))
} }
testFile := filepath.Join(tmpDir, "many.go") testFile := filepath.Join(tmpDir, "many.go")
if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil { if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil {
@@ -281,7 +281,7 @@ func TestSessionPrefsMaxResultsExplicitOverride(t *testing.T) {
var sb strings.Builder var sb strings.Builder
sb.WriteString("package main\n\n") sb.WriteString("package main\n\n")
for i := 0; i < 5; i++ { for i := 0; i < 5; i++ {
sb.WriteString(fmt.Sprintf("func Fn%c() {}\n\n", rune('A'+i))) fmt.Fprintf(&sb, "func Fn%c() {}\n\n", rune('A'+i))
} }
testFile := filepath.Join(tmpDir, "many.go") testFile := filepath.Join(tmpDir, "many.go")
if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil { if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil {
+5 -5
View File
@@ -77,24 +77,24 @@ func (e *StructuredError) Error() string {
var sb strings.Builder var sb strings.Builder
// Error code and message // Error code and message
sb.WriteString(fmt.Sprintf("[%d] %s", e.Code, e.Message)) fmt.Fprintf(&sb, "[%d] %s", e.Code, e.Message)
// Context if available // Context if available
if len(e.Context) > 0 { if len(e.Context) > 0 {
sb.WriteString("\nContext:") sb.WriteString("\nContext:")
for k, v := range e.Context { for k, v := range e.Context {
sb.WriteString(fmt.Sprintf("\n %s: %v", k, v)) fmt.Fprintf(&sb, "\n %s: %v", k, v)
} }
} }
// Remediation if available // Remediation if available
if e.Remediation != "" { if e.Remediation != "" {
sb.WriteString(fmt.Sprintf("\nHow to fix: %s", e.Remediation)) fmt.Fprintf(&sb, "\nHow to fix: %s", e.Remediation)
} }
// Underlying cause if available // Underlying cause if available
if e.Cause != nil { if e.Cause != nil {
sb.WriteString(fmt.Sprintf("\nCaused by: %v", e.Cause)) fmt.Fprintf(&sb, "\nCaused by: %v", e.Cause)
} }
return sb.String() return sb.String()
@@ -215,7 +215,7 @@ func captureStack(skip int) string {
for { for {
frame, more := frames.Next() frame, more := frames.Next()
if !strings.Contains(frame.File, "runtime/") { if !strings.Contains(frame.File, "runtime/") {
sb.WriteString(fmt.Sprintf("\n %s:%d %s", frame.File, frame.Line, frame.Function)) fmt.Fprintf(&sb, "\n %s:%d %s", frame.File, frame.Line, frame.Function)
} }
if !more { if !more {
break break