close

prefer-string-trim-start-end

Unreleased

Configuration

PresetConfigured Value
✅ unicornPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, unicornPlugin } from '@rslint/core';

export default defineConfig([
  unicornPlugin.configs.recommended,
  {
    rules: {
      'unicorn/prefer-string-trim-start-end': 'error',
    },
  },
]);

Rule Details

Prefer String#trimStart() and String#trimEnd() over the legacy String#trimLeft() and String#trimRight() aliases. The preferred names are direction-independent and therefore clearer for both left-to-right and right-to-left text.

Examples of incorrect code for this rule:

const leading = value.trimLeft();
const trailing = value.trimRight();

Examples of correct code for this rule:

const leading = value.trimStart();
const trailing = value.trimEnd();

Optional access is checked, while an optional call is left unchanged:

value?.trimLeft(); // Reported and fixed to value?.trimStart()
value.trimLeft?.(); // Allowed

Original Documentation