menu
prefer-string-replace-all
Prefer String.replaceAll when every occurrence is replaced
A global replacement or split-and-join chain expresses replacement of every occurrence indirectly.
Instead, you SHOULD use String.replaceAll to state that operation directly.
Splitting on an empty string has different behavior and is left unchanged.
Reported
1function redact(text: string): string {2 return text.replace(/secret/g, "***");3}Accepted
1function redact(text: string): string {2 return text.replaceAll(/secret/g, "***");3}