guard-for-in doesn't recognize that Object.entries() is returning an array for for...in loop
See original GitHub issue- ESLint Version: 4.14.0
- Node Version: v8.0.0
- npm Version: 5.6.0 What parser (default, Babel-ESLint, etc.) are you using? babel-eslint 8.1.2
Configuration
```js { "extends": "airbnb-base", "parser": "babel-eslint", "env": { "jest": true }, "rules": { "arrow-parens": "off", "no-throw-literal": "error", "no-void": "off", "import/prefer-default-export": "off", "valid-jsdoc": "error", "no-unused-expressions": [ "error", { "allowShortCircuit": true, "allowTernary": true } ] } } ```for (const file in Object.entries(newMockFiles)) {
...
}
Command ran:
eslint src
What did you expect to happen?
No linting error. The linter should recognize that the for...in
is iterating over an array.
What actually happened? Please include the actual, raw output from ESLint. error The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype guard-for-in
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
What is wrong looping with Object.entries? - Stack Overflow
I found here how I can loop in React return , so, that not only the key is available as with Object.keys() ,...
Read more >Object.entries() - JavaScript - MDN Web Docs
The Object.entries() method returns an array of a given object's own enumerable string-keyed property key-value pairs.
Read more >Loop Through an Object in JavaScript – How to Iterate Over ...
The Object.keys() method was introduced in ES6. It takes the object we want to loop over as an argument and returns an array...
Read more >How to loop through an array containing multiple objects and ...
entries() method in JavaScript returns an array consisting of enumerable property [key, value] pairs of the object. we iterate through that ...
Read more >How to loop through objects in JavaScript? - Flexiple
Learn the older and newer methods to loop over objects using javascript and the ... To loop over the array returned by Object.entries(), ......
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 see an error when I have something in the body, whether working with an array-returning function or an array literal. Demo here.
I don’t think the rule was designed to care about the type of the iterated object. So I’m having a hard time seeing this as a bug.
Closing because this is working as intended.