The same string literal is written more times than the configured maximum in one file
What it finds
A string that appears again and again, such as a key, a header name or a message, must be changed in every place at once, and a typo in one copy goes unnoticed. A named constant gives it one place and a name.
String literals of at least five characters that contain a letter are counted in each file; import paths and struct tags are not counted. The fourth occurrence, and with it every later one, is reported when the parameter max_repeats is 3, the default. Test files, whose tables repeat values by nature, are left alone.
From the rule's source, repeated_string_literal.rs.
package p func f(m map[string]string) { m["content-type"] = "a" m["content-type"] = "b" m["content-type"] = "c" m["content-type"] = "d"tx0 reports: appears 4 times in this file m["x"] = "y"} 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:repeated-string-literal" = "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:repeated-string-literal] reason="..."tx0 explain tx0/go:repeated-string-literal shows the same in the terminal. Found a false positive? Report it.