Skip to content

Commit

Permalink
Add no-iterator-helpers rules (#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
ota-meshi authored Nov 1, 2024
1 parent 7887af8 commit 58029a5
Show file tree
Hide file tree
Showing 56 changed files with 4,694 additions and 265 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
"javascript",
"vue"
],
"typescript.tsdk": "node_modules/typescript/lib",
}
28 changes: 28 additions & 0 deletions docs/configs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,34 @@ export default [
}
```

## no-iterator-helpers

disallow proposal ES2025 [Iterator Helpers](https://github.com/tc39/proposal-iterator-helpers)\
⚠️ This config will be changed in the minor versions of this plugin.

This configs includes rules for [es-x/no-iterator-prototype-drop](../rules/no-iterator-prototype-drop.md), [es-x/no-iterator-prototype-every](../rules/no-iterator-prototype-every.md), [es-x/no-iterator-prototype-filter](../rules/no-iterator-prototype-filter.md), [es-x/no-iterator-prototype-find](../rules/no-iterator-prototype-find.md), [es-x/no-iterator-prototype-flatmap](../rules/no-iterator-prototype-flatmap.md), [es-x/no-iterator-prototype-foreach](../rules/no-iterator-prototype-foreach.md), [es-x/no-iterator-prototype-map](../rules/no-iterator-prototype-map.md), [es-x/no-iterator-prototype-reduce](../rules/no-iterator-prototype-reduce.md), [es-x/no-iterator-prototype-some](../rules/no-iterator-prototype-some.md), [es-x/no-iterator-prototype-take](../rules/no-iterator-prototype-take.md), [es-x/no-iterator-prototype-toarray](../rules/no-iterator-prototype-toarray.md), and [es-x/no-iterator](../rules/no-iterator.md).

### [Config (Flat Config)]

eslint.config.js:

```js
import pluginESx from "eslint-plugin-es-x"
export default [
pluginESx.configs['flat/no-iterator-helpers']
]
```

### [Legacy Config]

.eslintrc.*:

```json
{
"extends": ["plugin:es-x/no-iterator-helpers"],
}
```

## no-set-methods

disallow proposal ES2025 [Set Methods for JavaScript](https://github.com/tc39/proposal-set-methods)\
Expand Down
14 changes: 13 additions & 1 deletion docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,20 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]

| Rule ID | Description | |
|:--------|:------------|:--:|
| [es-x/no-dynamic-import-options](./no-dynamic-import-options.md) | disallow second parameter to `import()`. | |
| [es-x/no-dynamic-import-options](./no-dynamic-import-options.md) | disallow the second parameter to `import()`. | |
| [es-x/no-import-attributes](./no-import-attributes.md) | disallow Import Attributes. | |
| [es-x/no-iterator-prototype-drop](./no-iterator-prototype-drop.md) | disallow the `Iterator.prototype.drop` method. | |
| [es-x/no-iterator-prototype-every](./no-iterator-prototype-every.md) | disallow the `Iterator.prototype.every` method. | |
| [es-x/no-iterator-prototype-filter](./no-iterator-prototype-filter.md) | disallow the `Iterator.prototype.filter` method. | |
| [es-x/no-iterator-prototype-find](./no-iterator-prototype-find.md) | disallow the `Iterator.prototype.find` method. | |
| [es-x/no-iterator-prototype-flatmap](./no-iterator-prototype-flatmap.md) | disallow the `Iterator.prototype.flatMap` method. | |
| [es-x/no-iterator-prototype-foreach](./no-iterator-prototype-foreach.md) | disallow the `Iterator.prototype.forEach` method. | |
| [es-x/no-iterator-prototype-map](./no-iterator-prototype-map.md) | disallow the `Iterator.prototype.map` method. | |
| [es-x/no-iterator-prototype-reduce](./no-iterator-prototype-reduce.md) | disallow the `Iterator.prototype.reduce` method. | |
| [es-x/no-iterator-prototype-some](./no-iterator-prototype-some.md) | disallow the `Iterator.prototype.some` method. | |
| [es-x/no-iterator-prototype-take](./no-iterator-prototype-take.md) | disallow the `Iterator.prototype.take` method. | |
| [es-x/no-iterator-prototype-toarray](./no-iterator-prototype-toarray.md) | disallow the `Iterator.prototype.toArray` method. | |
| [es-x/no-iterator](./no-iterator.md) | disallow the `Iterator` class. | |
| [es-x/no-json-modules](./no-json-modules.md) | disallow JSON Modules. | |
| [es-x/no-promise-try](./no-promise-try.md) | disallow `Promise.try` function. | |
| [es-x/no-regexp-duplicate-named-capturing-groups](./no-regexp-duplicate-named-capturing-groups.md) | disallow RegExp duplicate named capturing groups. | |
Expand Down
4 changes: 2 additions & 2 deletions docs/rules/no-dynamic-import-options.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---
title: "es-x/no-dynamic-import-options"
description: "disallow second parameter to `import()`"
description: "disallow the second parameter to `import()`"
---

# es-x/no-dynamic-import-options
> disallow second parameter to `import()`
> disallow the second parameter to `import()`
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-import-attributes] and [no-new-in-esnext]
Expand Down
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-drop"
description: "disallow the `Iterator.prototype.drop` method"
---

# es-x/no-iterator-prototype-drop
> disallow the `Iterator.prototype.drop` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.drop`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-drop: error */
const result = naturals()
.drop(3);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-drop.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-drop.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-every.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-every"
description: "disallow the `Iterator.prototype.every` method"
---

# es-x/no-iterator-prototype-every
> disallow the `Iterator.prototype.every` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.every`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-every: error */
const result = naturals()
.every(n => n % 2);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-every.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-every.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-filter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-filter"
description: "disallow the `Iterator.prototype.filter` method"
---

# es-x/no-iterator-prototype-filter
> disallow the `Iterator.prototype.filter` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.filter`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-filter: error */
const result = naturals()
.filter(n => n % 2);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-filter.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-filter.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-find"
description: "disallow the `Iterator.prototype.find` method"
---

# es-x/no-iterator-prototype-find
> disallow the `Iterator.prototype.find` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.find`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-find: error */
const result = naturals()
.find(n => n % 2);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-find.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-find.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-flatmap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-flatmap"
description: "disallow the `Iterator.prototype.flatMap` method"
---

# es-x/no-iterator-prototype-flatmap
> disallow the `Iterator.prototype.flatMap` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.flatMap`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-flatmap: error */
const result = naturals()
.flatMap(n => [n, -n]);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-flatmap.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-flatmap.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-foreach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-foreach"
description: "disallow the `Iterator.prototype.forEach` method"
---

# es-x/no-iterator-prototype-foreach
> disallow the `Iterator.prototype.forEach` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.forEach`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-foreach: error */
const result = naturals()
.forEach(n => {/* ... */});

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-foreach.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-foreach.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-map"
description: "disallow the `Iterator.prototype.map` method"
---

# es-x/no-iterator-prototype-map
> disallow the `Iterator.prototype.map` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.map`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-map: error */
const result = naturals()
.map(n => n % 2);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-map.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-map.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
38 changes: 38 additions & 0 deletions docs/rules/no-iterator-prototype-reduce.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
title: "es-x/no-iterator-prototype-reduce"
description: "disallow the `Iterator.prototype.reduce` method"
---

# es-x/no-iterator-prototype-reduce
> disallow the `Iterator.prototype.reduce` method
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
- ✅ The following configurations enable this rule: [no-iterator-helpers] and [no-new-in-esnext]

This rule reports ES2025 [`Iterator.prototype.reduce`](https://github.com/tc39/proposal-iterator-helpers) as errors.\

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-prototype-reduce: error */
const result = naturals()
.reduce((sum, value) => sum + value, 3);

function* naturals() {
// ...
}
```

</eslint-playground>

## 📚 References

- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-prototype-reduce.js)
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-prototype-reduce.js)

[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
Loading

0 comments on commit 58029a5

Please sign in to comment.