Skip to content

Improvement: Report RegExp with global flag saved in a variable #592

Closed
@Belco90

Description

@Belco90

What rule do you want to change?

no-global-regexp-flag-in-query

Does this change cause the rule to produce more or fewer warnings?

More warnings

How will the change be implemented?

Right now, we are only checking the RegExp passed directly to Testing Library queries. If a variable is found, we should check what's the value held in it to report global flags there also.

Example code

it('should render a basic demo', () => {
  const countRegExp = /count/gi
  render(<App />)
  expect(screen.getByText(countRegExp)).toBeInTheDocument()
})

How does the current rule affect the code?

screen.getByText(countRegExp) should be reported.

How will the new rule affect the code?

N/A

Anything else?

No response

Do you want to submit a pull request to change the rule?

No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions