A regular expression has more groups, alternatives, classes and quantifiers than the configured maximum
What it finds
Long patterns are hard to read and to change safely, and their behaviour on unusual input is hard to predict. Splitting them, naming the parts or matching in several steps keeps each one understandable.
The complexity of a pattern is the number of its groups, alternatives beyond the first, character classes, quantifiers and back references. The limit is the parameter max (20 by default).
From the rule's source, regex_complexity.rs.
export const email = /^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;tx0 reports: this pattern has a complexity ofexport const word = /\w+/; Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:regex-complexity" = "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-complexity] reason="..."tx0 explain tx0/ts:regex-complexity shows the same in the terminal. Found a false positive? Report it.