Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Belco90 opened this issue May 24, 2022 · 2 comments · Fixed by #678
Closed

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

Belco90 opened this issue May 24, 2022 · 2 comments · Fixed by #678

Comments

@Belco90
Copy link
Member

Belco90 commented May 24, 2022

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

@Belco90 Belco90 added enhancement New feature or request triage Pending to be triaged by a maintainer labels May 24, 2022
@Belco90 Belco90 changed the title [Improvement] Report RegExp with global flag saved in a variable Improvement: Report RegExp with global flag saved in a variable May 25, 2022
@Belco90 Belco90 removed the triage Pending to be triaged by a maintainer label May 25, 2022
Belco90 pushed a commit that referenced this issue Oct 19, 2022
…e declarations (#678)

Closes #592

* fix: change function name to more informative and add JS Doc comment

* feat(no-global-regexp-flag-in-query): detect global regexp in variable declarations
@github-actions
Copy link

🎉 This issue has been resolved in version 5.8.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This issue has been resolved in version 6.0.0-alpha.14 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant