For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/typescript-eslint/prefer-includes.md.
close

prefer-includes

Added in v0.3.0

Configuration

PresetConfigured Value
✅ ts.configs.stylisticTypeChecked"error"
rslint.config.ts
import { defineConfig, ts } from '@rslint/core';

export default defineConfig([
  ts.configs.recommended,
  {
    rules: {
      '@typescript-eslint/prefer-includes': 'error',
    },
  },
]);

Rule Details

Disallow indexOf(...) !== -1 / indexOf(...) === -1 style checks when includes(...) expresses intent more clearly.

Examples of incorrect code for this rule:

if (arr.indexOf(value) !== -1) {
  doSomething();
}

Examples of correct code for this rule:

if (arr.includes(value)) {
  doSomething();
}

Original Documentation