Rule proposal: Prefer .includes()
#284
Labels
enhancement: new plugin rule
New rule request for eslint-plugin
package: eslint-plugin
Issues related to @typescript-eslint/eslint-plugin
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.
The text was updated successfully, but these errors were encountered: