Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 314272

Summary: [validation] Project scoped JavaScript validation preferences aren't used
Product: [WebTools] JSDT Reporter: Sven Asp <asp.sven>
Component: GeneralAssignee: Chris Jaun <cmjaun>
Status: NEW --- QA Contact: Chris Jaun <cmjaun>
Severity: normal    
Priority: P3 CC: cmjaun, linzuxiong1988, mauromol, thatnitind, thomas
Version: unspecified   
Target Milestone: Future   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Zip of sample project
none
Zip of sample project none

Description Sven Asp CLA 2010-05-25 09:54:43 EDT
Build Identifier: I20100513-1500

I don't get much out of the JavaScript validation. In particular, I'd like to get complaints about shadowing global variables or loosely defined variables. I don't get any errors or warning markers. The validator is running because it does detect things like undefined variable and variables that are never read.


Reproducible: Always

Steps to Reproduce:
1. Create a new workspace
2. Unzip the attached file and import the jsbug project
3. Observer the lack of warnings and errors in the testing.js file
Comment 1 Sven Asp CLA 2010-05-25 09:56:09 EDT
Created attachment 169830 [details]
Zip of sample project
Comment 2 Sven Asp CLA 2010-05-25 10:40:56 EDT
Found another related problem.

This statement:

if(foo == null) {
  foo.bar();
}

correctly reports "Null pointer access: The variable foo can only be null at this location". That's good. But this statement:

if(foo != null) {
  foo.bar();
}

gives exactly the same error. That's perhaps not so good.
Comment 3 Nitin Dahyabhai CLA 2010-05-25 14:22:18 EDT
Sven, are your JavaScript Errors/Warnings preferences set correctly?  A number of checks are disabled by default.

Comment 2 sounds like a separate problem.
Comment 4 Sven Asp CLA 2010-05-25 15:01:08 EDT
I have (In reply to comment #3)
> Sven, are your JavaScript Errors/Warnings preferences set correctly?  A number
> of checks are disabled by default.
> 
My workspace has "Enable JavaScript semantic validation" enabled. The attached sample project has project specific settings included. The "Loosely Declared, Globally Scoped Variable Usage" for instance, should be a warning. Same thing with "Local variable declaration hides another field or variable". I think the sample should get both warnings.

> Comment 2 sounds like a separate problem.

OK, so you want a separate bugzilla for that?
Comment 5 Nitin Dahyabhai CLA 2010-05-25 16:27:03 EDT
(In reply to comment #4)
> OK, so you want a separate bugzilla for that?

If you please.  The more specific a bug report is, the better.
Comment 6 Nitin Dahyabhai CLA 2010-05-25 18:05:01 EDT
(In reply to comment #4)
> My workspace has "Enable JavaScript semantic validation" enabled. The attached
> sample project has project specific settings included. The "Loosely Declared,
> Globally Scoped Variable Usage" for instance, should be a warning. Same thing
> with "Local variable declaration hides another field or variable". I think the
> sample should get both warnings.
> 
> > Comment 2 sounds like a separate problem.
> 
> OK, so you want a separate bugzilla for that?

Actually, it's missing the .settings/org.eclipse.wst.jsdt.core.prefs that would characterize project-specific validation settings.  The shadowing setting you mention is ignored by default.
Comment 7 Sven Asp CLA 2010-05-26 00:54:06 EDT
Created attachment 169932 [details]
Zip of sample project

In this new zip I have verified that the preferences file is present in the project. The project setting for the variables in question is "Error". Yet, I don't see any errors.
Comment 8 Nitin Dahyabhai CLA 2010-05-26 01:19:50 EDT
Which Error messages, specifically, were you expecting?
Comment 9 Thomas Hallgren CLA 2010-05-26 02:21:48 EDT
In testFunc1() I expect to see that a local variable is shadowing a global variable.

In the testFunc2(), varB is assigned but it doesn't exist. So that's a loosely defined variable. The return varB should also be flagged since varB might be uninitialized at that point. It's conditionally assigned.

I see no errors and no warnings but if I change the return in testFunc2() to

 return varC;

Then I see a warning "varC cannot be resolved" so I know that validation really is in effect.
Comment 10 Sven Asp CLA 2010-05-26 03:39:51 EDT
I'm not sure what the exact warning was but I distinctly remember getting warnings for variables that was never declared. I had code that contained:

for(i = 0; i < someMax; ++i) {
  //
}

and got warnings that the variable 'i' wasn't defined. This was very helpful since several JS interpreters considers that an error. testFunc2() with its assignment to varB has the same issue. varB doesn't exist prior to it's assignment in the if statement.
Comment 11 Sven Asp CLA 2010-05-26 15:01:32 EDT
I wrote some more tests. This:

function testFunc3() {
    for(varC = 0; varC < 3; ++varC) {
    }
}

correctly yields the error "The variable varC is Globaly Scoped."

this however:

function testFunc4() {
    varD = 0;
    for(; varD < 3; ++varD) {
    }
}

does not. Perhaps that can help narrowing the problem?
Comment 12 Sven Asp CLA 2010-06-02 07:52:50 EDT
Does anyone have some insight on this? Am I doing something wrong? Is this a regresssion? If so, what version can I use to make it work?
Comment 13 Chris Jaun CLA 2010-06-07 17:15:38 EDT
I think part of the problem here is the project specific settings for Errors/Warnings does not seem to be working.

When I went and adjusting the workspace settings I got the expected error in the first function.
Comment 14 Chris Jaun CLA 2010-06-07 17:17:05 EDT
Sven,

Did you create a new bug for the problem described in comment #2?

Thanks,
Chris
Comment 15 Sven Asp CLA 2010-06-07 18:07:51 EDT
(In reply to comment #14)
> Sven,
> 
> Did you create a new bug for the problem described in comment #2?
> 
Yes I did. Please see bug 314394.
Comment 16 Sven Asp CLA 2010-12-02 03:41:54 EST
Not sure why the title of this bugzilla was changed. How the settings are scoped is only a small part of the problem. See comment 9 and comment 11. I can't get that working regardless of if I use workspace or project settings.
Comment 17 Lin ZuXiong CLA 2012-01-18 20:34:55 EST
eclipse jee 3.7.1 ,too.
Comment 18 Lin ZuXiong CLA 2012-01-18 21:53:36 EST
I think the authors of JSDT donot know Javascript Language.

I suggest let us close the javascript validation. 
But eclipse jee 3.7.1 canot close JS validation.I close the Preference of
javascript validation and make the level be Ignore ,but eclipse Problems still 
reports the problems (errors and warnings) of Javascript type .

Guys , you all can import a js file ,like JQuery-1.x.min.js , so that you can find
too many errors.