no-unnecessary-string-trim
UnreleasedConfiguration
Rule details
This rule replaces trim() with trimStart() before startsWith() and
with trimEnd() before endsWith() when trimming the other side cannot
affect the result.
A second argument can make the other side of the string observable. So can
trailing whitespace in a prefix or leading whitespace in a suffix. The rule
also skips optional chaining on the call chain, trim() calls with arguments,
and search values whose primitive string form cannot be determined statically.
It skips trim() on schemas created with a string constructor from zod,
including schemas stored in local variables that are never reassigned.
Examples of incorrect code for this rule
Examples of correct code for this rule
Options
This rule has no options.
Differences from upstream
Rslint skips Zod string constructors called through a default import, a named
string import, TypeScript's import z = require('zod'), or bracket access
such as z['string'](). It also skips schemas built with constructor options
or stored in a local variable that is never reassigned. In these cases,
Unicorn v79.0.0 can suggest replacing trim() with trimStart() or
trimEnd(), which would throw when building the schema.
In JavaScript, Rslint also preserves trim() when JSDoc identifies the
receiver as a non-string value and it is stored in a let variable that is
never reassigned.
With a local type alias named z, Unicorn v79.0.0 offers a trimStart()
autofix for the schema below. Rslint skips the call because z.string()
still uses the Zod import at runtime.