A constant is passed as the string and a variable as the prefix or suffix
What it finds
strings.HasPrefix("https://", url): the string comes first and the prefix second, so this asks whether url is a prefix of the constant, which holds only for a few short values such as "http" or "". The arguments are usually swapped; code that completes a typed word against a fixed one asks this on purpose.
Reported are calls of HasPrefix, HasSuffix, TrimPrefix, TrimSuffix, CutPrefix and CutSuffix of strings whose first argument is a constant string of the file and whose second is not.
From the rule's source, swapped_prefix_arguments.rs.
package p import "strings" func secure(url string) bool { if strings.HasPrefix("https://", url) {tx0 reports: the constant is passed as the string and the variable as the affix return true } return strings.HasPrefix(url, "https://")} 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:swapped-prefix-arguments" = "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:swapped-prefix-arguments] reason="..."tx0 explain tx0/go:swapped-prefix-arguments shows the same in the terminal. Found a false positive? Report it.