# prefer-string-starts-ends-with

Prefer `startsWith` and `endsWith` for string boundary tests

Comparing a search index or extracted slice expresses a string boundary test through intermediate values.
Instead, you SHOULD use `startsWith` or `endsWith` to state the tested boundary directly.

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

## Reported

```ds title="main.ds"
function hasPrefix(text: string, prefix: string): boolean {
    return text.indexOf(prefix) === 0;
}
```

## Accepted

```ds title="main.ds"
function hasPrefix(text: string, prefix: string): boolean {
    return text.startsWith(prefix);
}
```

## Prior art

- [typescript-eslint · prefer-string-starts-ends-with](https://typescript-eslint.io/rules/prefer-string-starts-ends-with)
- [eslint-plugin-unicorn · prefer-string-starts-ends-with](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-starts-ends-with.md)

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