💼 This rule is enabled in the ✅ recommended
config.
🔧💡 This rule is automatically fixable by the --fix
CLI option and manually fixable by editor suggestions.
Prefer String#startsWith()
and String#endsWith()
over using a regex with /^foo/
or /foo$/
.
This rule is fixable, unless the matching object is known not a string.
const foo = /^bar/.test(baz);
const foo = /bar$/.test(baz);
const foo = baz.startsWith('bar');
const foo = baz.endsWith('bar');
const foo = baz?.startsWith('bar');
const foo = (baz ?? '').startsWith('bar');
const foo = String(baz).startsWith('bar');
const foo = /^bar/i.test(baz);