`prefer-at`: inconsistent behaviour on arrays and strings
evaluatingchange request
### Description
Prior to #3200, `prefer-at` was a simplicity rule, suggesting replacing the complicated `array[array.length - 1]` (and other even more cursed incantations) with the nice simple `array.at(-1)`. It didn't, by default, suggest replacing `array[1]` with `array.at(1)`, since that is (slightly) more verbose.
Now, `prefer-at` suggests replacing `"cow"[2]` with `"cow".at(2)`. I would suggest moving this behaviour behind the `checkAllIndexAccess` option, as it is for arrays.*
\* In a new project, I wouldn't particularly mind banning indexing in favour of `.at`, especially for TypeScript without `noUncheckedIndexAccess` enabled. But I maintain our ESLint config for 500 000 lines of largely legacy JS/TS, where we can't really do that.
### Examples
```js
// ❌
const foo = array[array.length - 1];
// ❌
const foo = 'string'['string'.length - 1];
// ✅
const foo = array[1];
// ✅
const foo = array.at(1);
// ✅
const foo = 'string'[1];
// ✅
const foo = 'string'.at(1);
```
### Additional Info
_No response_
0 条评论