An alternative of a regular expression repeats an earlier one, so it can never be the one that matches

tx0/kotlin:regex-duplicate-alternativestrictwarningreliability/strings-and-regexdepth fastbug

What it finds

(png|jpg|png) lists png twice. The second copy can never be the alternative that matches, since the first one is tried before it; it is usually a typo for another value that is now missing.

Reported is an alternative that is the same as an earlier one of the same choice.

From the rule's source, regex_patterns.rs.

Example from the rule's tests
val images = Regex("\\.(png|jpg|png)$")tx0 reports: an alternative of this regular expression repeats an earlier oneval fine = Regex("\\.(png|jpg|gif)$")
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 from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:regex-duplicate-alternative" = "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/kotlin:regex-duplicate-alternative] reason="..."

tx0 explain tx0/kotlin:regex-duplicate-alternative shows the same in the terminal. Found a false positive? Report it.