# 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.

- Category: style
- Level: warning
- Fix: automatic
- Scope: module

## Reported

```ds title="main.ds"
function redact(text: string): string {
    return text.replace(/secret/g, "***");
}
```

## Accepted

```ds title="main.ds"
function redact(text: string): string {
    return text.replaceAll(/secret/g, "***");
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-string-replace-all](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-replace-all.md)

[language/linter/src/rules/style/prefer_string_replace_all.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_string_replace_all.rs#L8)
