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