mixed-regexp-capture-types
What it does
Section titled “What it does”Reports a regexp literal that has both named groups ((?<name>...)) and plain groups ((...)).
Why it matters
Section titled “Why it matters”When a regexp has named groups, Ruby does not capture the plain groups, so $2 and match[2] are nil, which is not what the numbered group in the source suggests.
To fix, name every group you need, or use (?:...) for the ones you do not.
Example
Section titled “Example”...y = :ok.../(?<a>x)(y)//(?<a>x)(?:y)/...Configuration
Section titled “Configuration”ruby: lint: rules: mixed-regexp-capture-types: warn # off, warn (default), errorEnabled by the presets: ruby/rubocop.
Suppress one line with sudsy-disable-next-line mixed-regexp-capture-types in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| rubocop | Lint/MixedRegexpCaptureTypes |
full |