^ or $ applies to one alternative of a regular expression while it looks meant for all

tx0/ts:regex-anchor-scoperecommendedwarningbug

What it finds

/^yes|no$/: | binds weaker than anything else in a pattern, so ^ applies to the first alternative only and $ to the last. The pattern matches any text that starts with yes or ends with no, not the two words alone; /^(?:yes|no)$/ was meant.

A pattern is reported when it has several alternatives at the top level, the first starts with ^ or the last ends with $, and some alternative is not anchored on that side.

From the rule's source, regex_anchor_scope.rs.

Example from the rule's tests
const a = /^yes|no$/;tx0 reports: the anchors in this pattern apply only to the first or last alternativeconst b = /^(?:yes|no)$/;const c = /^a$|^b$/;const d = /cat|dog/;
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 recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/ts:regex-anchor-scope" = "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/ts:regex-anchor-scope] reason="..."

tx0 explain tx0/ts:regex-anchor-scope shows the same in the terminal. Found a false positive? Report it.