# manual-strip

Prefer prefix or suffix stripping over checking and slicing

Checking a string boundary before slicing it repeats the affix and its length across two operations.
Instead, you SHOULD use `stripPrefix` or `stripSuffix` to test and return the remainder together.

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

## Reported

```ds title="main.ds"
function removePrefix(text: string, prefix: string): string | undefined {
    return text.startsWith(prefix) ? text.slice(prefix.length) : undefined;
}
```

## Accepted

```ds title="main.ds"
function removePrefix(text: string, prefix: string): string | undefined {
    return text.stripPrefix(prefix);
}
```

## Prior art

- [Clippy · manual_strip](https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip)

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