强制使用“includes”方法而不是“indexOf”方法。
规则配置
// 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 };