Configuring inspection "Unresolved JavaScript variable" to recognize global variables from external files

I have a PHP/HTML page which has something like this:
<!DOCTYPE html>
<html>
<head>
<script src="/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
var foobar = 10;
</script>
<script src="/test.js" type="text/javascript"></script>
</head>
<body>
<button>Click me!</button>
</body>

and in test.js:

$('button').click(funtion() {
     alert(foobar);
});

"Unresolved JavaScript variable" inspection reports "foobar" variable in test.js as unresolved. Is it possible to configure this inspection (at least indirectly) to lookup global scope variables in all files (.js or .php/.html/etc with JavaScript)?
This would be really helpful and could be configured to be an error to quickly see where global JavaScript variables are not declared with the "var" keyword.

0
5 comments
Avatar
Maxim Mossienko

Add following code to comment, there is no option to lookup all html files
/*global foobar */

1
Avatar
Permanently deleted user
Thanks!
/*global foobar */  worked, and there should not be a space between "/*" and "global".
Is this construct documented somewhere?
0
Avatar
Permanently deleted user

Are there any support for unrecognized properties? For example in

/*global myGlobalVarDefinedElseWhere */
alert(myGlobalVarDefinedElseWhere.myProperty);

myProperty is treated as unrecognized.

2
Avatar
Permanently deleted user

For all who land here via search engines. "use strict" from ECMAScript 5 may also be helpfull.

0

Please sign in to leave a comment.