Rule proposal: `proper-object-iterable-methods`
See original GitHub issueFail
// Should use `Object.values`
for (const key of Object.keys(foo)) {
bar(foo[key]);
}
// Should use `Object.entries`
for (const key of Object.keys(foo)) {
bar(foo[key], key);
}
// Should use `Object.values`
const foo = Object.keys(bar).map(key => baz(bar[key]));
// Should use `Object.entries`
const foo = Object.keys(bar).map(key => baz(bar[key], key));
// Should use `Object.keys`
for (const [key] of Object.entries(foo)) {
bar(key);
}
Pass
for (const key of Object.keys(foo)) {
foo[key] = 'new value';
delete foo[key];
foo[key]++;
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:12 (3 by maintainers)
Top Results From Across the Web
ECMAScript proposal: iterator helpers - 2ality
In this blog post, we look at the ECMAScript proposal “Iterator helpers” by Gus ... This object has a method whose key is...
Read more >Rule proposal: prevent array, iterable and function spreads ...
es2015.iterable.d.ts . The converse rule of preventing objects being spread within an array seems unnecessary/out-of-scope, given that ...
Read more >Iteration protocols - JavaScript - MDN Web Docs
The iterator protocol defines a standard way to produce a sequence of values (either finite or infinite), and potentially a return value when ......
Read more >PEP 234 – Iterators - Python Enhancement Proposals
Looping is customized by providing a method that produces an iterator object. The iterator provides a get next value operation that produces ...
Read more >The Iterator Pattern - Python Design Patterns
The container must offer an __iter__() method that returns an iterator object. Supporting this method makes a container an iterable. Each iterator must...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we should also enforce
Object.keys
overObject.entries
in this caseSo better come up a better name cover all them.
proper-object-iterable-methods
?