prefer-string-trim-start-end

March 27, 2026 ยท View on GitHub

๐Ÿ“ Prefer String#trimStart() / String#trimEnd() over String#trimLeft() / String#trimRight().

๐Ÿ’ผ This rule is enabled in the following configs: โœ… recommended, โ˜‘๏ธ unopinionated.

๐Ÿ”ง This rule is automatically fixable by the --fix CLI option.

String#trimLeft() and String#trimRight() are aliases of String#trimStart() and String#trimEnd(). This is to ensure consistency and use direction-independent wording.

Examples

// โŒ
const foo = bar.trimLeft();

// โœ…
const foo = bar.trimStart();
// โŒ
const foo = bar.trimRight();

// โœ…
const foo = bar.trimEnd();