Closed
Description
This rule should prefer .includes()
over .indexOf()
when checking for existence. This would apply to the following types: String#includes
, Array#includes
, TypedArray#includes
, Buffer#includes
.
.includes()
cases:
'foobar'.indexOf('foo') !== -1
'foobar'.indexOf('foo') != -1
'foobar'.indexOf('foo') > -1
'foobar'.indexOf('foo') >= 0
These would negate .includes()
:
'foobar'.indexOf('foo') == -1
'foobar'.indexOf('foo') === -1
'foobar'.indexOf('foo') < 0
It would also be useful to catch cases where String#includes()
would be better than a regex: /\r\n/.test(foo);
=> foo.includes('\r\n');
This was originally proposed for inclusion in ESLint, but declined for lack of type knowledge in JS.