Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions docs/rules/no-array-string-prototype-at.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# es/no-array-string-prototype-at
> disallow the `{Array,String}.prototype.at()` methods

This rule reports ES2022 [`{Array,String,TypedArray}.prototype.at` methods](https://github.com/tc39/proposal-relative-indexing-method) as errors.

This rule is silent by default because it's hard to know types. You need to configure [the aggressive mode](../#the-aggressive-mode) or TypeScript in order to enable this rule.

## Examples

⛔ Examples of **incorrect** code for this rule:

<eslint-playground type="bad" code="/*eslint es/no-array-string-prototype-at: [error, { aggressive: true }] */
foo.at(-1)
'str'.at(-1)
" />

## 🔧 Options

This rule has an option.

```yml
rules:
es/no-array-string-prototype-at: [error, { aggressive: false }]
```

### aggressive: boolean

Configure the aggressive mode for only this rule.
This is prior to the `settings.es.aggressive` setting.

## 📚 References

- [Rule source](https://github.com/mysticatea/eslint-plugin-es/blob/v4.1.0/lib/rules/no-array-string-prototype-at.js)
- [Test source](https://github.com/mysticatea/eslint-plugin-es/blob/v4.1.0/tests/lib/rules/no-array-string-prototype-at.js)
53 changes: 53 additions & 0 deletions lib/rules/no-array-string-prototype-at.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* @author Yosuke Ota <https://github.com/ota-meshi>
* See LICENSE file in root directory for full license.
*/
"use strict"

const {
definePrototypeMethodHandler,
} = require("../util/define-prototype-method-handler")

module.exports = {
meta: {
docs: {
description:
"disallow the `{Array,String}.prototype.at()` methods.",
category: "ES2022",
recommended: false,
url:
"http://mysticatea.github.io/eslint-plugin-es/rules/no-array-string-prototype-at.html",
},
fixable: null,
messages: {
forbidden: "ES2022 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
aggressive: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return definePrototypeMethodHandler(context, {
Array: ["at"],
String: ["at"],
Int8Array: ["at"],
Uint8Array: ["at"],
Uint8ClampedArray: ["at"],
Int16Array: ["at"],
Uint16Array: ["at"],
Int32Array: ["at"],
Uint32Array: ["at"],
Float32Array: ["at"],
Float64Array: ["at"],
BigInt64Array: ["at"],
BigUint64Array: ["at"],
})
},
}
Loading