{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/2723","labels_url":"https://api.github.com/repos/eslint/eslint/issues/2723/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/2723/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/2723/events","html_url":"https://github.com/eslint/eslint/issues/2723","id":86110809,"number":2723,"title":"Rule suggestion: restrict in operator","user":{"login":"denis-sokolov","id":113721,"avatar_url":"https://avatars.githubusercontent.com/u/113721?v=3","gravatar_id":"","url":"https://api.github.com/users/denis-sokolov","html_url":"https://github.com/denis-sokolov","followers_url":"https://api.github.com/users/denis-sokolov/followers","following_url":"https://api.github.com/users/denis-sokolov/following{/other_user}","gists_url":"https://api.github.com/users/denis-sokolov/gists{/gist_id}","starred_url":"https://api.github.com/users/denis-sokolov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/denis-sokolov/subscriptions","organizations_url":"https://api.github.com/users/denis-sokolov/orgs","repos_url":"https://api.github.com/users/denis-sokolov/repos","events_url":"https://api.github.com/users/denis-sokolov/events{/privacy}","received_events_url":"https://api.github.com/users/denis-sokolov/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2015-06-08T09:57:21Z","updated_at":"2015-06-09T17:21:46Z","closed_at":"2015-06-08T17:28:04Z","body":"I would like to propose a warning for `bar in foo` where `bar` is a variable.\r\nI might be mistaken, but it's likely the author means `Object.prototype.hasOwnProperty.call(foo, bar)`.\r\nIn cases where the user actually wants to check for an inherited property existence, such as feature detects, usually the value is a constant: `if ('quux' in foo) f(foo.quux)`.\r\neslint codebase has 0 occurences of an `in` operator with a variable as the first operand.\r\n\r\nThe following examples would cause a warning:\r\n```javascript\r\nif (key in myDictionary) {\r\n}\r\n\r\nvar isWordMentioned = function(word){\r\n  return word in mentionedWords;\r\n};\r\n```\r\n\r\nThe following examples would not cause anything:\r\n```javascript\r\nfor (var key in obj) {\r\n}\r\n\r\nvar userWantsCookies = 'cookies' in userWishes;\r\n```\r\n\r\nUltimately I want to catch problems caused by using `{}` as maps where `Object.create(null)` or `new Map()` would be more fitting.\r\n\r\nFeedback is appreciated.\r\nTangentially related to #2693 as it's all caused by JS objects used as maps."},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/110438806","html_url":"https://github.com/eslint/eslint/issues/2723#issuecomment-110438806","issue_url":"https://api.github.com/repos/eslint/eslint/issues/2723","id":110438806,"user":{"login":"nzakas","id":38546,"avatar_url":"https://avatars.githubusercontent.com/u/38546?v=3","gravatar_id":"","url":"https://api.github.com/users/nzakas","html_url":"https://github.com/nzakas","followers_url":"https://api.github.com/users/nzakas/followers","following_url":"https://api.github.com/users/nzakas/following{/other_user}","gists_url":"https://api.github.com/users/nzakas/gists{/gist_id}","starred_url":"https://api.github.com/users/nzakas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nzakas/subscriptions","organizations_url":"https://api.github.com/users/nzakas/orgs","repos_url":"https://api.github.com/users/nzakas/repos","events_url":"https://api.github.com/users/nzakas/events{/privacy}","received_events_url":"https://api.github.com/users/nzakas/received_events","type":"User","site_admin":false},"created_at":"2015-06-09T17:21:46Z","updated_at":"2015-06-09T17:21:46Z","body":"Yes, I just think it's a huge leap to say using `in` is probably a mistake. \r\n\r\nRemember, the whole point of allowing custom rules is so you don't have to convince us of your point of view. You can still write a rule to do this, I just dying think it fits as a core rule "}}