{"action":"created","issue":{"url":"https://api.github.com/repos/jshint/jshint/issues/1320","labels_url":"https://api.github.com/repos/jshint/jshint/issues/1320/labels{/name}","comments_url":"https://api.github.com/repos/jshint/jshint/issues/1320/comments","events_url":"https://api.github.com/repos/jshint/jshint/issues/1320/events","html_url":"https://github.com/jshint/jshint/issues/1320","id":21447508,"number":1320,"title":"Function declaration incorrectly reported as unused when global variable exists","user":{"login":"Rob--W","id":1365071,"avatar_url":"https://avatars.githubusercontent.com/u/1365071?v=3","gravatar_id":"","url":"https://api.github.com/users/Rob--W","html_url":"https://github.com/Rob--W","followers_url":"https://api.github.com/users/Rob--W/followers","following_url":"https://api.github.com/users/Rob--W/following{/other_user}","gists_url":"https://api.github.com/users/Rob--W/gists{/gist_id}","starred_url":"https://api.github.com/users/Rob--W/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Rob--W/subscriptions","organizations_url":"https://api.github.com/users/Rob--W/orgs","repos_url":"https://api.github.com/users/Rob--W/repos","events_url":"https://api.github.com/users/Rob--W/events{/privacy}","received_events_url":"https://api.github.com/users/Rob--W/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2013-10-23T11:24:25Z","updated_at":"2015-06-25T15:16:33Z","closed_at":"2015-06-25T15:16:32Z","body":"```javascript\r\n/*1*/ /* jshint unused:true */\r\n/*2*/ /* globals y */\r\n/*3*/ (function() { \r\n/*4*/     'use strict';\r\n/*5*/     y(); // Call local function\r\n/*6*/     function y() { \r\n/*7*/     } \r\n/*8*/ })();\r\n/*9*/ y(); // Call global function\r\n```\r\nErrors:\r\n```\r\ny.js: line 6, col 15, 'y' is already defined.\r\ny.js: line 6, col 15, 'y' is defined but never used.\r\n```\r\nI expected no errors. Swapping the local function declaration and call results in no errors.\r\n\r\n```javascript\r\n/*1*/ /* jshint unused:true */\r\n/*2*/ /* globals y */\r\n/*3*/ (function() { \r\n/*4*/     'use strict';\r\n/*5*/     function y() {\r\n/*6*/     }\r\n/*7*/     y(); // Call local function\r\n/*8*/ })();\r\n/*9*/ y(); // Call global function\r\n```\r\n\r\nWhen another y is not declared globally, i.e. line 2 is removed, then the error also goes away (but a new error is rightfully raised about the use of an undefined y, at line 9).\r\n\r\n### Temporary work-around\r\nIn my real case, the variables were implicitly defined in `.jshintrc` using `devel:true`. In a node script, I declared a function called `prompt`, and called it a few lines back. This caused the error. A temporary work-around is to either rename the functions, or to insert\r\n```\r\n/* globals -alert */\r\n```\r\n\r\nat the top of the file."},"comment":{"url":"https://api.github.com/repos/jshint/jshint/issues/comments/115289326","html_url":"https://github.com/jshint/jshint/issues/1320#issuecomment-115289326","issue_url":"https://api.github.com/repos/jshint/jshint/issues/1320","id":115289326,"user":{"login":"lukeapage","id":309321,"avatar_url":"https://avatars.githubusercontent.com/u/309321?v=3","gravatar_id":"","url":"https://api.github.com/users/lukeapage","html_url":"https://github.com/lukeapage","followers_url":"https://api.github.com/users/lukeapage/followers","following_url":"https://api.github.com/users/lukeapage/following{/other_user}","gists_url":"https://api.github.com/users/lukeapage/gists{/gist_id}","starred_url":"https://api.github.com/users/lukeapage/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lukeapage/subscriptions","organizations_url":"https://api.github.com/users/lukeapage/orgs","repos_url":"https://api.github.com/users/lukeapage/repos","events_url":"https://api.github.com/users/lukeapage/events{/privacy}","received_events_url":"https://api.github.com/users/lukeapage/received_events","type":"User","site_admin":false},"created_at":"2015-06-25T15:16:32Z","updated_at":"2015-06-25T15:16:32Z","body":"Fixed by #2468 will be released in the next release (after 2.8.0)"}}