Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .changeset/no-iterator-concat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"eslint-plugin-es-x": minor
---

Add `es-x/no-iterator-concat` rule
1 change: 1 addition & 0 deletions docs/rules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
| [es-x/no-asyncdisposablestack](./no-asyncdisposablestack.md) | disallow the `AsyncDisposableStack` class. | |
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
| [es-x/no-iterator-concat](./no-iterator-concat.md) | disallow the `Iterator.concat` method. | |
| [es-x/no-math-sumprecise](./no-math-sumprecise.md) | disallow the `Math.sumPrecise` method. | |
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
| [es-x/no-symbol-asyncdispose](./no-symbol-asyncdispose.md) | disallow the `Symbol.asyncDispose` property. | |
Expand Down
54 changes: 54 additions & 0 deletions docs/rules/no-iterator-concat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
title: "es-x/no-iterator-concat"
description: "disallow the `Iterator.concat` method"
---

# es-x/no-iterator-concat
> disallow the `Iterator.concat` 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-new-in-esnext]

This rule reports ES2026 [`Iterator.concat` method](https://github.com/tc39/proposal-iterator-sequencing) as errors.

## 💡 Examples

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

<eslint-playground type="bad">

```js
/*eslint es-x/no-iterator-concat: error */
Iterator.concat();
```

</eslint-playground>

## 🔧 Options

This rule has an option.

```jsonc
{
"rules": {
"es-x/no-iterator-concat": [
"error",
{
"allowTestedProperty": false
}
]
}
}
```

### allowTestedProperty: boolean

Configure the allowTestedProperty mode for only this rule.
This is prior to the `settings['es-x'].allowTestedProperty` setting.

## 📚 References

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

[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext
1 change: 1 addition & 0 deletions lib/configs/flat/no-new-in-esnext.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
"es-x/no-asyncdisposablestack": "error",
"es-x/no-disposablestack": "error",
"es-x/no-error-iserror": "error",
"es-x/no-iterator-concat": "error",
"es-x/no-math-sumprecise": "error",
"es-x/no-suppressederror": "error",
"es-x/no-symbol-asyncdispose": "error",
Expand Down
1 change: 1 addition & 0 deletions lib/configs/no-new-in-esnext.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
"es-x/no-asyncdisposablestack": "error",
"es-x/no-disposablestack": "error",
"es-x/no-error-iserror": "error",
"es-x/no-iterator-concat": "error",
"es-x/no-math-sumprecise": "error",
"es-x/no-suppressederror": "error",
"es-x/no-symbol-asyncdispose": "error",
Expand Down
1 change: 1 addition & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ module.exports = {
"no-intl-segmenter": require("./rules/no-intl-segmenter"),
"no-intl-supportedvaluesof": require("./rules/no-intl-supportedvaluesof"),
"no-iterator": require("./rules/no-iterator"),
"no-iterator-concat": require("./rules/no-iterator-concat"),
"no-iterator-prototype-drop": require("./rules/no-iterator-prototype-drop"),
"no-iterator-prototype-every": require("./rules/no-iterator-prototype-every"),
"no-iterator-prototype-filter": require("./rules/no-iterator-prototype-filter"),
Expand Down
35 changes: 35 additions & 0 deletions lib/rules/no-iterator-concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"use strict"

const {
defineStaticPropertiesHandler,
} = require("../util/define-static-properties-handler")

module.exports = {
meta: {
docs: {
description: "disallow the `Iterator.concat` method",
category: "ES2026",
recommended: false,
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-iterator-concat.html",
},
fixable: null,
messages: {
forbidden: "ES2026 '{{name}}' method is forbidden.",
},
schema: [
{
type: "object",
properties: {
allowTestedProperty: { type: "boolean" },
},
additionalProperties: false,
},
],
type: "problem",
},
create(context) {
return defineStaticPropertiesHandler(context, {
Iterator: { concat: "function" },
})
},
}
1 change: 1 addition & 0 deletions lib/util/well-known-properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ const iteratorProperties = new Set([
...functionPrototypeProperties,

// https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-properties-of-the-iterator-constructor
"concat",
"from",
"prototype",
])
Expand Down
2 changes: 1 addition & 1 deletion scripts/update-docs-rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ async function main() {
const since = getSince(originalContent)

let content = originalContent
.replace(/^\n*(?:---[\s\S]*?---\n\n?)?#.+\n>.+\n+(?:- .+\n)*/u, "")
.replace(/^\n*(?:---[\s\S]*?---\n\n?)?#.+\n>.*\n+(?:- .+\n)*/u, "")
.replace(/## 🚀 Version[\s\S]+/u, "")
.replace(/## 📚 References[\s\S]+/u, "")
.trim()
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/rules/no-iterator-concat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
"use strict"

const RuleTester = require("../../tester")
const rule = require("../../../lib/rules/no-iterator-concat.js")

new RuleTester().run("no-iterator-concat", rule, {
valid: ["Iterator", "Iterator.length", "let Iterator = 0; Iterator.concat"],
invalid: [
{
code: "Iterator.concat",
errors: ["ES2026 'Iterator.concat' method is forbidden."],
},
],
})
Loading