# prefer-string-trim-start-end

Rule `unicorn/prefer-string-trim-start-end`. Prefer `String#trimStart()` / `String#trimEnd()` over `String#trimLeft()` / `String#trimRight()`.

- Source: unicorn
- Technologies: JavaScript
- Kind: style
- Needs type information: no
- Autofix: yes, in at least one linter
- Reach: 12M weekly downloads of presets that enable it
- Trend: +40.1% last quarter
- Rank: #759 by reach, #955 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `unicorn/prefer-string-trim-start-end` | no | safe | package `eslint-plugin-unicorn` | [docs](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/v80.0.0/docs/rules/prefer-string-trim-start-end.md) |
| Oxlint | `unicorn/prefer-string-trim-start-end` | no | safe | plugin `unicorn`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/unicorn/prefer-string-trim-start-end.html) |
| Biome | `style/useTrimStartEnd` | no | safe | group style, since 1.9.0 | [docs](https://biomejs.dev/linter/rules/use-trim-start-end/) |

## Code examples

### Incorrect: the rule reports this

```js
const name = '  John  '.trimLeft();
```

```js
const value = text.trimRight();
```

### Correct: the rule accepts this

```js
const name = '  John  '.trimStart();
```

```js
const value = text.trimEnd();
```

```js
const str = '  hello world  ';
str.trim();      // Remove from both sides
str.trimStart(); // Remove from beginning
str.trimEnd();   // Remove from end
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import unicorn from "eslint-plugin-unicorn";

export default [
  {
    plugins: { unicorn },
    rules: {
      "unicorn/prefer-string-trim-start-end": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "rules": {
    "unicorn/prefer-string-trim-start-end": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "style": {
        "useTrimStartEnd": "error"
      }
    }
  }
}
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [Unicorn recommended](https://lintradar.dev/presets/unicorn-recommended.md) | ESLint | `eslint-plugin-unicorn` | 340 | 9.5M | +30.3% |
| [Unicorn unopinionated](https://lintradar.dev/presets/unicorn-unopinionated.md) | ESLint | `eslint-plugin-unicorn` | 236 | 9.5M | +30.3% |
| [Ultracite for Biome](https://lintradar.dev/presets/ultracite-biome.md) | Biome | `ultracite` | 616 | 2.1M | +151.7% |
| [Ultracite for Oxlint](https://lintradar.dev/presets/ultracite-oxlint.md) | Oxlint | `ultracite` | 475 | 2.1M | +151.7% |
| [XO](https://lintradar.dev/presets/xo.md) | ESLint | `eslint-config-xo` | 618 | 413K | −5.0% |

## Related rules

- [unicorn/prefer-string-slice](https://lintradar.dev/rules/unicorn/prefer-string-slice.md): Prefer `String#slice()` over `String#substr()` and `String#substring()`.
- [unicorn/require-number-to-fixed-digits-argument](https://lintradar.dev/rules/unicorn/require-number-to-fixed-digits-argument.md): Enforce using the digits argument with `Number#toFixed()`.
- [unicorn/prefer-regexp-test](https://lintradar.dev/rules/unicorn/prefer-regexp-test.md): Prefer `RegExp#test()` over `String#match()`, `String#search()`, and `RegExp#exec()`.
- [unicorn/consistent-existence-index-check](https://lintradar.dev/rules/unicorn/consistent-existence-index-check.md): Enforce consistent style for element existence checks with `indexOf()`, `lastIndexOf()`, `findIndex()`, and `findLastIndex()`.
- [unicorn/prefer-module](https://lintradar.dev/rules/unicorn/prefer-module.md): Prefer JavaScript modules (ESM) over CommonJS.
- [unicorn/filename-case](https://lintradar.dev/rules/unicorn/filename-case.md): Enforce a case style for filenames and directory names.

---

Web page: https://lintradar.dev/rules/unicorn/prefer-string-trim-start-end. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
