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

Rule proposal: no-missing-g-flag #472

Closed
fisker opened this issue Nov 3, 2022 · 1 comment · Fixed by #474
Closed

Rule proposal: no-missing-g-flag #472

fisker opened this issue Nov 3, 2022 · 1 comment · Fixed by #474
Labels
enhancement New feature or request new rule

Comments

@fisker
Copy link

fisker commented Nov 3, 2022

Motivation

When calling String#replaceAll() and String#matchAll() with non-global RegExp, it will be a runtime error. I hope to catch this pattern during linting.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replaceAll#exceptions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/matchAll#exceptions

Description

Forbid calling String#replaceAll() or String#matchAll() with non-global pattern.

Examples

/* ✓ GOOD */
foo.replaceAll(" ", '')
foo.replaceAll(/\s/g, '')
foo.matchAll(/\s/g)

/* ✗ BAD */
foo.replaceAll(/\s/, '')
foo.matchAll(/\s/)
@fisker fisker added enhancement New feature or request new rule labels Nov 3, 2022
@ota-meshi
Copy link
Owner

Thank you for the rule suggestions! That rule sounds good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request new rule
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants