A function that compares or replaces is given the same expression twice
What it finds
bytes.Equal(a, a), strings.ReplaceAll(s, old, old) or copy(dst, dst): comparing a value with itself is always true, replacing a text with itself and copying a slice onto itself change nothing. One of the two arguments was meant to be something else.
The function must be the builtin copy, or one of strings and bytes that compares two texts or replaces one by another, reflect.DeepEqual, errors.Is, math.Max or math.Min, resolved through the imports of the file. The two arguments must consist of the same tokens and contain no calls or receives, which could give a different value each time.
From the rule's source, identical_arguments.rs.
package p import ( "bytes" "reflect" "strings") func f(a, b []byte, s, old string, x, y any) bool { copy(a, a)tx0 reports: copy is given a twice s = strings.ReplaceAll(s, old, old)tx0 reports: strings.ReplaceAll is given old twice if bytes.Equal(a, a) {tx0 reports: bytes.Equal is given a twice return true } copy(a, b) s = strings.ReplaceAll(s, old, "new") return reflect.DeepEqual(x, y) || bytes.Equal(next(), next())} func next() []byte { return nil } Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/go:identical-arguments" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/go:identical-arguments] reason="..."tx0 explain tx0/go:identical-arguments shows the same in the terminal. Found a false positive? Report it.