eslint/no-iterator 正しさ
何を検出するか
__iterator__ プロパティの使用を禁止します。
なぜ問題か
__iterator__ プロパティは、スパイダーマンク(SpiderMonkey)が拡張した JavaScript の機能であり、for in や for each 構文と互換性を持つカスタムイテレータを作成するために利用されていました。しかし、このプロパティは現在非推奨となっており、使用すべきではありません。以下は当時どのように動作していたかの例です:
js
Foo.prototype.__iterator__ = function () {
return new FooIterator(this);
};例
このルールに違反する 誤り なコードの例:
javascript
Foo.prototype.__iterator__ = function () {
return new FooIterator(this);
};
foo.__iterator__ = function () {};
foo["__iterator__"] = function () {};このルールに従う 正しい コードの例:
js
const __iterator__ = 42; // __iterator__ プロパティを使用していない
Foo.prototype[Symbol.iterator] = function () {
return new FooIterator(this);
};使用方法
設定ファイルまたは CLI でこのルールを 有効化 するには、次のようにします:
json
{
"rules": {
"no-iterator": "error"
}
}bash
oxlint --deny no-iterator