A FindAll method of a regular expression is asked for at most zero matches

tx0/go:find-all-count-zerodefaultwarningbug

What it finds

re.FindAllString(s, 0): the last argument of the FindAll methods of a regular expression is the most matches to return, and a negative number means all of them, so 0 asks for none and the call always returns nil.

Reported are calls of the methods FindAll, FindAllIndex, FindAllString, FindAllStringIndex, FindAllSubmatch, FindAllSubmatchIndex, FindAllStringSubmatch and FindAllStringSubmatchIndex with the literal 0 as their second argument, in a file that imports regexp.

From the rule's source, find_all_count_zero.rs.

Example from the rule's tests
package p import "regexp" var digits = regexp.MustCompile(`\d+`) func f(s string) ([]string, [][]int) {	all := digits.FindAllString(s, 0)tx0 reports: FindAllString with a count of 0 never returns a match	_ = digits.FindAllString(s, -1)	return all, digits.FindAllStringIndex(s, 0)tx0 reports: FindAllStringIndex with a count of 0}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/go:find-all-count-zero" = "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:find-all-count-zero] reason="..."

tx0 explain tx0/go:find-all-count-zero shows the same in the terminal. Found a false positive? Report it.