Skip to content

New rule: no-global-regex-flag-to-query #559

@timdeschryver

Description

@timdeschryver

Name for new rule

no-global-regex-flag-to-query

Description of the new rule

The rule would warn when a user uses the global regex flag to search for text/name.
A regex that uses the global flag holds the lastIndex state when it found a match, due to this it could be that a new match can't be found.

See testing-library/dom-testing-library#1116 for the fix within DTL, where we added a log when we detect this.

Testing Library feature

Queries that use a regex

Testing Library framework(s)

All

What category of rule is this?

Suggests an alternate way of doing something

Optional: other category of rule

No response

Code examples

screen.getAllByText(/hello world/g)
screen.findByRole('button', {name: /log in/ig})

Anything else?

No response

Do you want to submit a pull request to make the new rule?

Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    new ruleNew rule to be included in the pluginreleased

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions