-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
167 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
--- | ||
title: "es-x/no-iterator" | ||
description: "disallow the `Iterator` class" | ||
--- | ||
|
||
# es-x/no-iterator | ||
> disallow the `Iterator` class | ||
- ❗ <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` class as errors.\ | ||
The `Iterator` class was added in the ES2025 [Iterator Helpers proposal](https://github.com/tc39/proposal-iterator-helpers). | ||
|
||
## 💡 Examples | ||
|
||
⛔ Examples of **incorrect** code for this rule: | ||
|
||
<eslint-playground type="bad"> | ||
|
||
```js | ||
/*eslint es-x/no-iterator: error */ | ||
const wrapper = Iterator.from(iter); | ||
``` | ||
|
||
</eslint-playground> | ||
|
||
## 📚 References | ||
|
||
- [Rule source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/lib/rules/no-iterator.js) | ||
- [Test source](https://github.com/eslint-community/eslint-plugin-es-x/blob/master/tests/lib/rules/no-iterator.js) | ||
|
||
[no-iterator-helpers]: ../configs/index.md#no-iterator-helpers | ||
[no-new-in-esnext]: ../configs/index.md#no-new-in-esnext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* DON'T EDIT THIS FILE. | ||
* This file was generated by "scripts/update-lib-flat-configs.js" script. | ||
*/ | ||
"use strict" | ||
|
||
module.exports = { | ||
plugins: { | ||
get "es-x"() { | ||
return require("../../index.js") | ||
}, | ||
}, | ||
rules: { "es-x/no-iterator": "error" }, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* DON'T EDIT THIS FILE. | ||
* This file was generated by "scripts/update-lib-configs.js" script. | ||
*/ | ||
"use strict" | ||
|
||
module.exports = { plugins: ["es-x"], rules: { "es-x/no-iterator": "error" } } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"use strict" | ||
|
||
const { READ, ReferenceTracker } = require("@eslint-community/eslint-utils") | ||
const { getSourceCode } = require("eslint-compat-utils") | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: "disallow the `Iterator` class.", | ||
category: "ES2025", | ||
proposal: "iterator-helpers", | ||
recommended: false, | ||
url: "http://eslint-community.github.io/eslint-plugin-es-x/rules/no-iterator.html", | ||
}, | ||
fixable: null, | ||
messages: { | ||
forbidden: "ES2025 '{{name}}' class is forbidden.", | ||
}, | ||
schema: [], | ||
type: "problem", | ||
}, | ||
create(context) { | ||
return { | ||
"Program:exit"(program) { | ||
const sourceCode = getSourceCode(context) | ||
const tracker = new ReferenceTracker( | ||
sourceCode.getScope(program), | ||
) | ||
for (const { node, path } of tracker.iterateGlobalReferences({ | ||
Iterator: { [READ]: true }, | ||
})) { | ||
context.report({ | ||
node, | ||
messageId: "forbidden", | ||
data: { name: path.join(".") }, | ||
}) | ||
} | ||
}, | ||
} | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
"use strict" | ||
|
||
const RuleTester = require("../../tester") | ||
const rule = require("../../../lib/rules/no-iterator.js") | ||
|
||
if (!RuleTester.isSupported(2025)) { | ||
//eslint-disable-next-line no-console | ||
console.log("Skip the tests of no-iterator.") | ||
return | ||
} | ||
|
||
new RuleTester({ | ||
languageOptions: { globals: { Iterator: "readonly" } }, | ||
}).run("no-iterator", rule, { | ||
valid: [ | ||
"Array.from(object)", | ||
"const Iterator = Array; Iterator.from(object)", | ||
], | ||
invalid: [ | ||
{ | ||
code: "Iterator.from(object)", | ||
errors: ["ES2025 'Iterator' class is forbidden."], | ||
}, | ||
{ | ||
code: "Iterator", | ||
errors: ["ES2025 'Iterator' class is forbidden."], | ||
}, | ||
], | ||
}) |