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

Enforce .replaceAll() over .replace() when the pattern has g flag #1948

Closed
fisker opened this issue Nov 7, 2022 · 3 comments · Fixed by #1965
Closed

Enforce .replaceAll() over .replace() when the pattern has g flag #1948

fisker opened this issue Nov 7, 2022 · 3 comments · Fixed by #1965

Comments

@fisker
Copy link
Collaborator

fisker commented Nov 7, 2022

I believe they are the same, but use .replaceAll() has more clear intention

Fail

foo.replace(/\s/g, '')

Pass

foo.replaceAll(/\s/g, '')
foo.replace(/\s/, '')
foo.replace(" ", '')
@sindresorhus
Copy link
Owner

Accepted.

@kachkaev
Copy link
Contributor

Do both foo.replaceAll(/\s/g, '') and foo.replaceAll(/\s/, '') pass? Feels like there should be one style or another everywhere.

@fisker
Copy link
Collaborator Author

fisker commented Nov 21, 2022

foo.replaceAll(/\s/, '') is a runtime error. ota-meshi/eslint-plugin-regexp#472

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