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 270718 - Need codefix for undeclared variable
Summary: Need codefix for undeclared variable
Status: NEW
Alias: None
Product: javascript
Classification: Unclassified
Component: Editor (show other bugs)
Version: Dev
Hardware: PC Other
: P3 normal (vote)
Assignee: Petr Pisl
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-05-23 13:30 UTC by Christian Lenz
Modified: 2017-05-23 13:30 UTC (History)
0 users

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments
undeclared variable handling in WebStorm (28.52 KB, image/png)
2017-05-23 13:30 UTC, Christian Lenz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Christian Lenz 2017-05-23 13:30:54 UTC
Created attachment 164384 [details]
undeclared variable handling in WebStorm

Often you see a variable, which is global and/or not declared. NB will show this to you as a warning, error, info or suggestion for the selected line which is good but it should be not only a hint, it should be a fix too to declare the variable. Or to create a param inside a method. I added a screenshot from WebStorm and it does it as I expected.



function test() {
   foo = 1; // Var is global or not declared HINT!
}

Fixes for the Hint:
   Fix1: declare variable as var, let or const. I think one type is ok one fix for 
         each type would be awesome.

after the fix:
var foo // e.g.


   Fix 2: create param

after the fix:
function test(foo) {
   foo = 1;
}


   Fix 3: Ignore it, make it global for JSHint

This is already given BUT the problem is, that it will add it into the file as a comment. Not each teammember is amused of this behaviour, so it should be a similar functionality as in HTML for custom elements. Those elements will be written into a custom.json file and will not throw an error anymore.

It should be declared per project AND globally in the options, because often, like in test files you have common patterns like beforeEach, it, describe, etc. Such keywords should be known from the IDE because of the framework. Some others should be declared as global inside the project and/or global inside the options.


Regards

Chris