Enforce the includes method over the indexOf method.
// code-linter.json5
{
"rules": {
"@typescript-eslint/prefer-includes": "error"
}
} const str: string = 'hello';
const array: string[] = ['hello'];
const readonlyArray: readonly string[] = ['hello'];
str.includes('h');
array.includes('h');
readonlyArray.includes('h'); const str: string = 'hello';
const array: string[] = ['hello'];
const readonlyArray: readonly string[] = ['hello'];
const num = -1;
let vv = str.indexOf('h') !== num;
vv = vv && array.indexOf('h') !== num;
vv = vv && readonlyArray.indexOf('h') !== num;
export { vv }; plugin:@typescript-eslint/all
For details about how to configure Code Linter check rules, see Code Linter.