diff --git a/.changeset/no-iterator-concat.md b/.changeset/no-iterator-concat.md new file mode 100644 index 00000000..8480fbe7 --- /dev/null +++ b/.changeset/no-iterator-concat.md @@ -0,0 +1,5 @@ +--- +"eslint-plugin-es-x": minor +--- + +Add `es-x/no-iterator-concat` rule diff --git a/docs/rules/index.md b/docs/rules/index.md index e41eb3c4..06ef6060 100644 --- a/docs/rules/index.md +++ b/docs/rules/index.md @@ -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. | | diff --git a/docs/rules/no-iterator-concat.md b/docs/rules/no-iterator-concat.md new file mode 100644 index 00000000..5ce34a18 --- /dev/null +++ b/docs/rules/no-iterator-concat.md @@ -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 + +- ❗ ***This rule has not been released yet.*** +- ✅ 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: + + + +```js +/*eslint es-x/no-iterator-concat: error */ +Iterator.concat(); +``` + + + +## 🔧 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 diff --git a/lib/configs/flat/no-new-in-esnext.js b/lib/configs/flat/no-new-in-esnext.js index 83add688..5c815d87 100644 --- a/lib/configs/flat/no-new-in-esnext.js +++ b/lib/configs/flat/no-new-in-esnext.js @@ -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", diff --git a/lib/configs/no-new-in-esnext.js b/lib/configs/no-new-in-esnext.js index 95318be3..24278c1e 100644 --- a/lib/configs/no-new-in-esnext.js +++ b/lib/configs/no-new-in-esnext.js @@ -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", diff --git a/lib/index.js b/lib/index.js index 6b97d1b6..d8f22660 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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"), diff --git a/lib/rules/no-iterator-concat.js b/lib/rules/no-iterator-concat.js new file mode 100644 index 00000000..4ec3f849 --- /dev/null +++ b/lib/rules/no-iterator-concat.js @@ -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" }, + }) + }, +} diff --git a/lib/util/well-known-properties.js b/lib/util/well-known-properties.js index 68838e03..73463ea0 100644 --- a/lib/util/well-known-properties.js +++ b/lib/util/well-known-properties.js @@ -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", ]) diff --git a/scripts/update-docs-rules.js b/scripts/update-docs-rules.js index 624490b5..45363642 100644 --- a/scripts/update-docs-rules.js +++ b/scripts/update-docs-rules.js @@ -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() diff --git a/tests/lib/rules/no-iterator-concat.js b/tests/lib/rules/no-iterator-concat.js new file mode 100644 index 00000000..c26a1757 --- /dev/null +++ b/tests/lib/rules/no-iterator-concat.js @@ -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."], + }, + ], +})