Skip to content

Commit e48f044

Browse files
authored
Add es-x/no-iterator-concat rule (#300)
1 parent b13e399 commit e48f044

File tree

10 files changed

+114
-1
lines changed

10 files changed

+114
-1
lines changed

.changeset/no-iterator-concat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"eslint-plugin-es-x": minor
3+
---
4+
5+
Add `es-x/no-iterator-concat` rule

docs/rules/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ There is a config that enables the rules in this category: [`no-new-in-esnext`]
1414
| [es-x/no-asyncdisposablestack](./no-asyncdisposablestack.md) | disallow the `AsyncDisposableStack` class. | |
1515
| [es-x/no-disposablestack](./no-disposablestack.md) | disallow the `DisposableStack` class. | |
1616
| [es-x/no-error-iserror](./no-error-iserror.md) | disallow the `Error.isError` method. | |
17+
| [es-x/no-iterator-concat](./no-iterator-concat.md) | disallow the `Iterator.concat` method. | |
1718
| [es-x/no-math-sumprecise](./no-math-sumprecise.md) | disallow the `Math.sumPrecise` method. | |
1819
| [es-x/no-suppressederror](./no-suppressederror.md) | disallow the `SuppressedError` class. | |
1920
| [es-x/no-symbol-asyncdispose](./no-symbol-asyncdispose.md) | disallow the `Symbol.asyncDispose` property. | |

docs/rules/no-iterator-concat.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: "es-x/no-iterator-concat"
3+
description: "disallow the `Iterator.concat` method"
4+
---
5+
6+
# es-x/no-iterator-concat
7+
> disallow the `Iterator.concat` method
8+
9+
- ❗ <badge text="This rule has not been released yet." vertical="middle" type="error"> ***This rule has not been released yet.*** </badge>
10+
- ✅ The following configurations enable this rule: [no-new-in-esnext]
11+
12+
This rule reports ES2026 [`Iterator.concat` method](https://github.com/tc39/proposal-iterator-sequencing) as errors.
13+
14+
## 💡 Examples
15+
16+
⛔ Examples of **incorrect** code for this rule:
17+
18+
<eslint-playground type="bad">
19+
20+
```js
21+
/*eslint es-x/no-iterator-concat: error */
22+
Iterator.concat();
23+
```
24+
25+
</eslint-playground>
26+
27+
## 🔧 Options
28+
29+
This rule has an option.
30+
31+
```jsonc
32+
{
33+
"rules": {
34+
"es-x/no-iterator-concat": [
35+
"error",
36+
{
37+
"allowTestedProperty": false
38+
}
39+
]
40+
}
41+
}
42+
```
43+
44+
### allowTestedProperty: boolean
45+
46+
Configure the allowTestedProperty mode for only this rule.
47+
This is prior to the `settings['es-x'].allowTestedProperty` setting.
48+
49+
## 📚 References
50+
51+
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator-concat.js)
52+
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator-concat.js)
53+
54+
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext

lib/configs/flat/no-new-in-esnext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module.exports = {
1515
"es-x/no-asyncdisposablestack": "error",
1616
"es-x/no-disposablestack": "error",
1717
"es-x/no-error-iserror": "error",
18+
"es-x/no-iterator-concat": "error",
1819
"es-x/no-math-sumprecise": "error",
1920
"es-x/no-suppressederror": "error",
2021
"es-x/no-symbol-asyncdispose": "error",

lib/configs/no-new-in-esnext.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
"es-x/no-asyncdisposablestack": "error",
1212
"es-x/no-disposablestack": "error",
1313
"es-x/no-error-iserror": "error",
14+
"es-x/no-iterator-concat": "error",
1415
"es-x/no-math-sumprecise": "error",
1516
"es-x/no-suppressederror": "error",
1617
"es-x/no-symbol-asyncdispose": "error",

lib/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ module.exports = {
258258
"no-intl-segmenter": require("./rules/no-intl-segmenter"),
259259
"no-intl-supportedvaluesof": require("./rules/no-intl-supportedvaluesof"),
260260
"no-iterator": require("./rules/no-iterator"),
261+
"no-iterator-concat": require("./rules/no-iterator-concat"),
261262
"no-iterator-prototype-drop": require("./rules/no-iterator-prototype-drop"),
262263
"no-iterator-prototype-every": require("./rules/no-iterator-prototype-every"),
263264
"no-iterator-prototype-filter": require("./rules/no-iterator-prototype-filter"),

lib/rules/no-iterator-concat.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"use strict"
2+
3+
const {
4+
defineStaticPropertiesHandler,
5+
} = require("../util/define-static-properties-handler")
6+
7+
module.exports = {
8+
meta: {
9+
docs: {
10+
description: "disallow the `Iterator.concat` method",
11+
category: "ES2026",
12+
recommended: false,
13+
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-iterator-concat.html",
14+
},
15+
fixable: null,
16+
messages: {
17+
forbidden: "ES2026 '{{name}}' method is forbidden.",
18+
},
19+
schema: [
20+
{
21+
type: "object",
22+
properties: {
23+
allowTestedProperty: { type: "boolean" },
24+
},
25+
additionalProperties: false,
26+
},
27+
],
28+
type: "problem",
29+
},
30+
create(context) {
31+
return defineStaticPropertiesHandler(context, {
32+
Iterator: { concat: "function" },
33+
})
34+
},
35+
}

lib/util/well-known-properties.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,7 @@ const iteratorProperties = new Set([
868868
...functionPrototypeProperties,
869869

870870
// https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-properties-of-the-iterator-constructor
871+
"concat",
871872
"from",
872873
"prototype",
873874
])

scripts/update-docs-rules.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ async function main() {
6767
const since = getSince(originalContent)
6868

6969
let content = originalContent
70-
.replace(/^\n*(?:---[\s\S]*?---\n\n?)?#.+\n>.+\n+(?:- .+\n)*/u, "")
70+
.replace(/^\n*(?:---[\s\S]*?---\n\n?)?#.+\n>.*\n+(?:- .+\n)*/u, "")
7171
.replace(/## 🚀 Version[\s\S]+/u, "")
7272
.replace(/## 📚 References[\s\S]+/u, "")
7373
.trim()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict"
2+
3+
const RuleTester = require("../../tester")
4+
const rule = require("../../../lib/rules/no-iterator-concat.js")
5+
6+
new RuleTester().run("no-iterator-concat", rule, {
7+
valid: ["Iterator", "Iterator.length", "let Iterator = 0; Iterator.concat"],
8+
invalid: [
9+
{
10+
code: "Iterator.concat",
11+
errors: ["ES2026 'Iterator.concat' method is forbidden."],
12+
},
13+
],
14+
})

0 commit comments

Comments
 (0)