This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 268969 - Unused variable warning works on globals only when the word "exports" is somewhere in the file
Summary: Unused variable warning works on globals only when the word "exports" is some...
Status: RESOLVED WONTFIX
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: 8.2
Hardware: PC Linux
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-11-14 11:15 UTC by riksoft
Modified: 2016-11-25 15:34 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description riksoft 2016-11-14 11:15:46 UTC
var aaa = 1;
var bbb = 2;

function foo() {
  //If I uncomment any of the following lines,
  //the warning of unused variables appears on aaa and bbb, otherwise no warning.

  // exports;
  // var x=exports;
  // console.log(exports);
  // foo2(exports);
  // alert(exports);
  // if(x==exports){};

};


function foo2(a){
}


Is it normal?
Comment 1 Petr Pisl 2016-11-25 09:13:48 UTC
From an unknown reason the variables are private, when you uncomment a line. I'm going to look at this.
Comment 2 Petr Pisl 2016-11-25 09:26:29 UTC
The problem is in using exports. The nodejs support thinks that due to  existing object "exports" in the code it is a node js module. So then the code is wrapped in a function and the variables aaa and bbb starts to be private and unused. If you don't want to use nodejs support you can switch it off in the plugin manager.
Comment 3 riksoft 2016-11-25 09:48:15 UTC
I don't see node.js in the list of installed plugins,
however, If I get it right, you are telling me that the correct behaviour is when the global variables don't get the warning because Netbeans is not intended to check usage of global variables?

If so, isn't there an option to have the same behaviour of node.js having the warning if the global variable is not used in such file unless declared with /* global var_name */?
Comment 4 Petr Pisl 2016-11-25 10:16:20 UTC
Basically you are right. The global variables are not check with the unused hint. There checked whether are defined. And this hint use the /* global var_name */ comment. 

In this case node js support finds extends global variable and it changed the model of the source to corresponds to the nodejs module. In such case all previous global variables are local, because are not visible outside the module and other features don't know that were global.  

And I'm sorry, it looks like the nodejs support is not really accessible in the plugin manager. I will fix it in different issue #269114.
Comment 5 riksoft 2016-11-25 12:07:16 UTC
Well, actually this problem could be a feature then.... I mean, if I want to check whether a global variable is used in a file, with this bug I only have to write "// exports;" somewhere in the file all the global variables are checked in seconds. Without this bug I should use "Find" var by var. :-)

Do you know any other official way to have the global variables checked?
Comment 6 Petr Pisl 2016-11-25 13:09:09 UTC
Aha, now I probably understand. You are want to check whether the global variable is used in the file. 

Could you put new enhancement for it? I will try to implement such option. Thanks
Comment 7 riksoft 2016-11-25 15:34:36 UTC
Here we go...
https://netbeans.org/bugzilla/show_bug.cgi?id=269119

Many thanks!