question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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 } ] } } ```
**What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.**
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:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Jan 5, 2018

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.

0reactions
not-an-aardvarkcommented, Mar 5, 2018

Closing because this is working as intended.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found