sindresorhus/eslint-plugin-unicorn

`prefer-includes` rule #8

sindresorhus posted onGitHub

Prefer .includes() over .indexOf() when checking for existence. Since ESLint has no type analysis we'll have to assume all properties named .indexOf() have a .includes() counterpart. This is luckily true for all builtins: String#includes, Array#includes, TypedArray#includes, Buffer#includes.

See https://github.com/eslint/eslint/issues/4209 for more.

.includes() cases:

  • 'foobar'.indexOf('foo') !== -1
  • 'foobar'.indexOf('foo') != -1
  • 'foobar'.indexOf('foo') > -1
  • 'foobar'.indexOf('foo') >= 0

New to making ESLint rules? Check out this quick guide on how to get started.


Fund this Issue

$42.00
Rewarded

Rewarded pull request

Recent activities

prbart was rewarded by sindresorhus for sindresorhus/eslint-plugin-unicorn# 8
almost 6 years ago
prbart submitted an output to  sindresorhus/ eslint-plugin-unicorn# 8
almost 6 years ago