{"action":"created","issue":{"url":"https://api.github.com/repos/eslint/eslint/issues/3964","labels_url":"https://api.github.com/repos/eslint/eslint/issues/3964/labels{/name}","comments_url":"https://api.github.com/repos/eslint/eslint/issues/3964/comments","events_url":"https://api.github.com/repos/eslint/eslint/issues/3964/events","html_url":"https://github.com/eslint/eslint/issues/3964","id":108676313,"number":3964,"title":"Don't add event as global when browser: true","user":{"login":"kileras","id":881852,"avatar_url":"https://avatars.githubusercontent.com/u/881852?v=3","gravatar_id":"","url":"https://api.github.com/users/kileras","html_url":"https://github.com/kileras","followers_url":"https://api.github.com/users/kileras/followers","following_url":"https://api.github.com/users/kileras/following{/other_user}","gists_url":"https://api.github.com/users/kileras/gists{/gist_id}","starred_url":"https://api.github.com/users/kileras/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kileras/subscriptions","organizations_url":"https://api.github.com/users/kileras/orgs","repos_url":"https://api.github.com/users/kileras/repos","events_url":"https://api.github.com/users/kileras/events{/privacy}","received_events_url":"https://api.github.com/users/kileras/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/eslint/eslint/labels/triage","name":"triage","color":"cc317c"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-09-28T15:02:18Z","updated_at":"2015-09-28T15:40:40Z","closed_at":null,"body":"Right now when you configure your env with \"browser: true\" you will get a event variable automatically added to your globals so this would lint perfectly despite event not being defined (tested in the online demo):\r\n\r\n```\r\n/*eslint-env browser */\r\n\r\nfunction a() {\r\n  var b = event.target;\r\n  return b;\r\n}\r\n\r\na();\r\n```\r\n\r\nI think that this is incorrect as the event variable is only defined inside an event context, so its not totally global and may end up preventing eslint form catching some potential undefined variables.\r\n\r\nAlso, and the actual reason why I discovered this, in some contexts the event parameter and the event global may not be the same thing. For example in React they are using some fake nodes to dispatch events (I find it a bit odd but this or another similar code may still be a valid use case) and they do a bind to override the event value as seen here: https://github.com/facebook/react/blob/8c75e792abf54f34b7a36a777826f104d1e0fb34/src/shared/utils/ReactErrorUtils.js#L68 . In that case if you use the global event instead of the parameter you will get a fake <react></react> node instead of the target and you won't figure out until one hour later :smile:\r\n\r\nFor that cases if you don't think that removing the global event for the browsers is a good idea, potentially for compatibility reasons, maybe adding an specific rule to forbid the use of global event variables would be a good idea so eslint can handle this situations a bit better.\r\n\r\n<bountysource-plugin>\r\n---\r\nWant to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/27003903-don-t-add-event-as-global-when-browser-true?utm_campaign=plugin&utm_content=tracker%2F282608&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F282608&utm_medium=issues&utm_source=github).\r\n</bountysource-plugin>"},"comment":{"url":"https://api.github.com/repos/eslint/eslint/issues/comments/143782734","html_url":"https://github.com/eslint/eslint/issues/3964#issuecomment-143782734","issue_url":"https://api.github.com/repos/eslint/eslint/issues/3964","id":143782734,"user":{"login":"michaelficarra","id":218840,"avatar_url":"https://avatars.githubusercontent.com/u/218840?v=3","gravatar_id":"","url":"https://api.github.com/users/michaelficarra","html_url":"https://github.com/michaelficarra","followers_url":"https://api.github.com/users/michaelficarra/followers","following_url":"https://api.github.com/users/michaelficarra/following{/other_user}","gists_url":"https://api.github.com/users/michaelficarra/gists{/gist_id}","starred_url":"https://api.github.com/users/michaelficarra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/michaelficarra/subscriptions","organizations_url":"https://api.github.com/users/michaelficarra/orgs","repos_url":"https://api.github.com/users/michaelficarra/repos","events_url":"https://api.github.com/users/michaelficarra/events{/privacy}","received_events_url":"https://api.github.com/users/michaelficarra/received_events","type":"User","site_admin":false},"created_at":"2015-09-28T15:40:40Z","updated_at":"2015-09-28T15:40:40Z","body":"> I think that this is incorrect as the event variable is only defined inside an event context\r\n\r\nNot true, it is always there. Run `\"event\" in this` in your console."}}