π Disallow String#trim() before String#startsWith() or String#endsWith().
πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§ This rule is automatically fixable by the --fix CLI option.
Use String#trimStart() before String#startsWith() and String#trimEnd() before String#endsWith() when the search value's string form cannot observe the opposite side.
This rule does not report startsWith() or endsWith() calls with a second argument, because the second argument can make the other side of the string observable.
This rule also does not report trim() calls with arguments, optional chaining, search values that cannot be resolved statically, startsWith() search values whose string form ends in whitespace, or endsWith() search values whose string form starts with whitespace.
// β
const result = value.trim().startsWith('-');
// β
const result = value.trimStart().startsWith('-');// β
const result = value.trim().endsWith('-');
// β
const result = value.trimEnd().endsWith('-');// β
const result = value.trim().startsWith('-', 1);// β
const result = value.trim().startsWith('foo ');