Skip to content

unicorn/prefer-string-trim-start-end Style

🛠️ An auto-fix is available for this rule.

What it does

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

Why is this bad?

The trimLeft and trimRight names are confusing and inconsistent with the rest of the language.

Example

Examples of incorrect code for this rule:

javascript
str.trimLeft();
str.trimRight();

Examples of correct code for this rule:

javascript
str.trimStart();
str.trimEnd();

References

Released under the MIT License.