Two functions of a file have the same parameters, results and body
What it finds
Two functions with the same body are copies: a fix made to one is easily missed in the other, and readers must compare them to see that they are the same. One can call the other, or both can share a helper.
Functions and methods of the file are compared by their parameter lists, results and bodies, token by token. Bodies with fewer than three statements are left alone, since short functions such as getters are often alike by nature; so are methods of different receiver types, which may have to look alike to satisfy an interface.
From the rule's source, identical_functions.rs.
package p func sumA(xs []int) int { total := 0 for _, x := range xs { total += x } return total} func sumB(xs []int) int {tx0 reports: sumB has the same parameters and body as sumA total := 0 for _, x := range xs { total += x } return total} func get() int { return 1 } func other() int { return 1 } Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:identical-functions" = "warning"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-functions] reason="..."tx0 explain tx0/go:identical-functions shows the same in the terminal. Found a false positive? Report it.