Cutset Duplicates

ID

go.cutset_duplicates

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Go

Tags

reliability, suspicious-comparison

Description

Reports a strings.Trim, strings.TrimLeft or strings.TrimRight call whose cutset string literal contains a repeated character.

Rationale

The cutset argument of these functions is a set of code points to strip, not a substring. Listing the same character twice does nothing beyond the first occurrence, so a duplicate is dead weight and usually signals a typo or the mistaken belief that the function removes a whole substring. Flagging it surfaces the misunderstanding before it hides a real bug.

// Bad
strings.Trim(s, "  ")      // space listed twice
strings.TrimLeft(s, "//")  // slash listed twice

// Good
strings.Trim(s, " ")
strings.TrimPrefix(s, "//") // if a leading "//" substring was actually intended

Remediation

Remove the duplicate characters from the cutset. If a whole prefix or suffix substring was meant to be removed, use strings.TrimPrefix or strings.TrimSuffix instead.