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();

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny unicorn/prefer-string-trim-start-end
json
{
  "rules": {
    "unicorn/prefer-string-trim-start-end": "error"
  }
}

References

Released under the MIT License.