mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-18 05:48:00 +00:00
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:
+16
-16
@@ -278,27 +278,27 @@ func (r *Registry) Expose() string {
|
||||
// Export counters
|
||||
for _, c := range r.counters {
|
||||
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))
|
||||
sb.WriteString(fmt.Sprintf("%s%s %d\n", c.name, formatLabels(c.labels), c.value.Load()))
|
||||
fmt.Fprintf(&sb, "# TYPE %s counter\n", c.name)
|
||||
fmt.Fprintf(&sb, "%s%s %d\n", c.name, formatLabels(c.labels), c.value.Load())
|
||||
}
|
||||
|
||||
// Export gauges
|
||||
for _, g := range r.gauges {
|
||||
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))
|
||||
sb.WriteString(fmt.Sprintf("%s%s %d\n", g.name, formatLabels(g.labels), g.value.Load()))
|
||||
fmt.Fprintf(&sb, "# TYPE %s gauge\n", g.name)
|
||||
fmt.Fprintf(&sb, "%s%s %d\n", g.name, formatLabels(g.labels), g.value.Load())
|
||||
}
|
||||
|
||||
// Export histograms
|
||||
for _, h := range r.histograms {
|
||||
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
|
||||
var cumulative int64
|
||||
@@ -306,26 +306,26 @@ func (r *Registry) Expose() string {
|
||||
cumulative += h.counts[i].Load()
|
||||
labelStr := formatLabels(h.labels)
|
||||
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 {
|
||||
// Insert le label into existing labels
|
||||
sb.WriteString(fmt.Sprintf("%s_bucket%s %d\n", h.name,
|
||||
strings.Replace(labelStr, "}", fmt.Sprintf(",le=\"%g\"}", bound), 1), cumulative))
|
||||
fmt.Fprintf(&sb, "%s_bucket%s %d\n", h.name,
|
||||
strings.Replace(labelStr, "}", fmt.Sprintf(",le=\"%g\"}", bound), 1), cumulative)
|
||||
}
|
||||
}
|
||||
// +Inf bucket
|
||||
cumulative += h.counts[len(h.buckets)].Load()
|
||||
labelStr := formatLabels(h.labels)
|
||||
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 {
|
||||
sb.WriteString(fmt.Sprintf("%s_bucket%s %d\n", h.name,
|
||||
strings.Replace(labelStr, "}", ",le=\"+Inf\"}", 1), cumulative))
|
||||
fmt.Fprintf(&sb, "%s_bucket%s %d\n", h.name,
|
||||
strings.Replace(labelStr, "}", ",le=\"+Inf\"}", 1), cumulative)
|
||||
}
|
||||
|
||||
// Sum and count
|
||||
sb.WriteString(fmt.Sprintf("%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_sum%s %g\n", h.name, formatLabels(h.labels), h.Sum())
|
||||
fmt.Fprintf(&sb, "%s_count%s %d\n", h.name, formatLabels(h.labels), h.count.Load())
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
|
||||
@@ -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 {
|
||||
lines := strings.Split(string(content), "\n")
|
||||
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 {
|
||||
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 != "" {
|
||||
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) {
|
||||
sb.WriteString(lines[s.Location.Line-1] + " { ... }\n")
|
||||
|
||||
@@ -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).
|
||||
wantVerbose := len(verbose) > 0 && verbose[0]
|
||||
if wantVerbose {
|
||||
sb.WriteString(fmt.Sprintf("Found %d match(es):\n", renderCount))
|
||||
fmt.Fprintf(&sb, "Found %d match(es):\n", renderCount)
|
||||
}
|
||||
|
||||
switch format {
|
||||
@@ -498,13 +498,13 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
|
||||
nodeType = r.Node.Type()
|
||||
}
|
||||
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":
|
||||
for i := 0; i < renderCount; 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"
|
||||
@@ -514,7 +514,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
|
||||
if r.Node != nil {
|
||||
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
|
||||
text := r.Text
|
||||
@@ -538,7 +538,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
|
||||
if len(capText) > 50 {
|
||||
capText = capText[:50] + "..."
|
||||
}
|
||||
sb.WriteString(fmt.Sprintf("$%s=%s", name, capText))
|
||||
fmt.Fprintf(&sb, "$%s=%s", name, capText)
|
||||
}
|
||||
sb.WriteString("\n")
|
||||
}
|
||||
@@ -549,7 +549,7 @@ func FormatResultsWithOptions(results []MatchResult, maxResults int, format stri
|
||||
if remaining > 0 {
|
||||
// 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.
|
||||
sb.WriteString(fmt.Sprintf("[remaining: %d]\n", remaining))
|
||||
fmt.Fprintf(&sb, "[remaining: %d]\n", remaining)
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
|
||||
@@ -389,13 +389,13 @@ func (s *Searcher) FormatResultsWithOptions(results *SearchResults, opts FormatO
|
||||
if opts.Verbose {
|
||||
totalMatches := len(results.Results)
|
||||
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 {
|
||||
sb.WriteString(fmt.Sprintf(" (truncated, total: %d)", results.Total))
|
||||
fmt.Fprintf(&sb, " (truncated, total: %d)", results.Total)
|
||||
}
|
||||
sb.WriteString(":\n\n")
|
||||
} 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
|
||||
@@ -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 {
|
||||
writeClusteredResults(&sb, fileResults[file])
|
||||
|
||||
@@ -199,7 +199,7 @@ func TestSessionPrefsASTQueryMaxResults(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("package main\n\n")
|
||||
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")
|
||||
if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil {
|
||||
@@ -281,7 +281,7 @@ func TestSessionPrefsMaxResultsExplicitOverride(t *testing.T) {
|
||||
var sb strings.Builder
|
||||
sb.WriteString("package main\n\n")
|
||||
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")
|
||||
if err := os.WriteFile(testFile, []byte(sb.String()), 0600); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user