Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sindresorhus/eslint-plugin-unicorn/llms.txt

Use this file to discover all available pages before exploring further.

Use .includes() instead of comparing the result of .indexOf() or .lastIndexOf() against -1 or 0. Also prefer .includes() over a simple Array#some() callback that only checks for strict equality. All built-in strings and arrays support .includes(), which reads as plain English and expresses intent directly.
Recommendedrecommended · ☑️ unopinionated
Fixable🔧 Auto-fixable
Suggestions💡 Has suggestions
This rule is fixable unless the search expression in Array#some() has side effects. Calls to _.indexOf(), lodash.indexOf(), and underscore.indexOf() are intentionally ignored.

Examples

// indexOf comparisons
array.indexOf('foo') !== -1;
array.indexOf('foo') != -1;
array.indexOf('foo') >= 0;
array.indexOf('foo') > -1;

// lastIndexOf
array.lastIndexOf('foo') !== -1;

// Array#some with simple equality
array.some(x => x === 'foo');
array.some(x => 'foo' === x);
array.some(x => {
  return x === 'foo';
});

// Works for strings too
string.indexOf('foo') !== -1;
string.lastIndexOf('foo') !== -1;

// Negation — indexOf === -1
foo.indexOf('foo') === -1;

Build docs developers (and LLMs) love