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.

Examples

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 using the config file or in the CLI, you can use:

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

References

Released under the MIT License.