eclipsesource / jshint-eclipse

JSHint integration for the Eclipse IDE
http://github.eclipsesource.com/jshint-eclipse/
146 stars 31 forks source link

undef: true not working #39

Closed machineghost closed 10 years ago

machineghost commented 11 years ago

I'm trying to get JSHint for Eclipse working, and for the most part it seems like it is. However, one really crucial part of it isn't working: catching undefined variable usage.

If I have a file like:

/*jshint undef: true */
a.b();

c

I would expect to see a warning next to both line 2 and line 4. However, I only see one on line 3 (apparently the "Missing semi-colon" warning blames the previous line).

I've tried adding that comment to the top of my files, adding undef: true in the preferences, using various forms of nested/un-nested variables, cleaning my build, restarting Eclipse, etc. all to no avail. No matter what I do, it seems that Eclise/JSHint just can't be bothered to care about my use of variables which don't exist.

machineghost commented 11 years ago

I just updated to Eclipse Juno (I had been using whatever version came before that), and now undef: true works great, so if anyone else out there has this issue ... upgrade :-)

machineghost commented 11 years ago

Looks like I spoke too soon; evidently the undef functionality only worked right after the install, or only works some of the time. I just tried a different file and, even though it's clearly referencing an undefined variable, I get no warning :-(

ralfstx commented 11 years ago

Can't reproduce. Tested with a fresh Eclipse 3.6.2, and jshint-eclipse 0.9.6. Created a new project with the file you provided. Also after restart and rebuild, I consistently get these 4 problems:

'a' is not defined  test.js /test   line 2  JSHint Problem
'c' is not defined  test.js /test   line 4  JSHint Problem
Expected an assignment or function call and instead saw an expression   test.js /test   line 4  JSHint Problem
Missing semicolon   test.js /test   line 4  JSHint Problem

I'll need further information how your problem can be reproduced.

machineghost commented 11 years ago

Hmmm ... I just went to reproduce my test case to "prove" you wrong, and ... it works perfectly, just as you said. Clearly there is some other factor involved (maybe something to do with my build not being clean?), and until I can provide that factor this issue will likely be impossible to reproduce.

So, I swear I did that exact test case in Eclipse and saw "undef" not work, but given that I can't explain how to reproduce it I guess I'll close this ticket for now (and then hopefully reopen it later once I have better repro instructions).

Thanks for your time.

machineghost commented 11 years ago

Ok, I just observed the problem again, and this time it's reproducible even if I restart Eclipse.

In short, I have Eclipse version 4.2.2, with JSHint version 0.9.6.2, and when I edit the following file

/*jshint undef:true */
define([], function() {
    'use strict';

    /**
     * @option model a SubObjectPattern instance
     */
    return ConstraintRow.extend({
        className: "constraint subObjectConstraint",
        template: subObjectConstraintRowTemplate,

        initialize: function(options) {
            this.validateModel();
            var label = new PropertyConstraintLabel({model: this.model}, {});
            this.templateData.label = label.html();
            this.templateData.title = this.model.get("title");
            var addButtonOptions = {collection: this.model.get("expression"),
                                    query: this.model.query};
            this.addButton = new AddConstraintButton(addButtonOptions);
        }
    });
});

the plug-in does not flag any of the missing variables (ConstraintRow, subObjectConstraintRowTemplate, PropertyConstraintLabel, and AddConstraintButton).

I have attached a screenshot to further demonstrate this issue, and if there's any further info I can provide please let me know.

jshintExample

ralfstx commented 11 years ago

Tried to reproduce again. Same file and version (0.9.6), I get warning markers for all these problems:

'AddConstraintButton' is not defined    test.js /_pasted_code_/src/snippet  line 19 JSHint Problem
'PropertyConstraintLabel' is not defined    test.js /_pasted_code_/src/snippet  line 14 JSHint Problem
'subObjectConstraintRowTemplate' is not defined test.js /_pasted_code_/src/snippet  line 10 JSHint Problem
'ConstraintRow' is not defined  test.js /_pasted_code_/src/snippet  line 8  JSHint Problem
'define' is not defined test.js /_pasted_code_/src/snippet  line 2  JSHint Problem

Please understand that the Eclipse plug-in does not perform any analysis itself, it delegates the work to jshint. If you suspect a problem related only to a certain config keyword, it's unlikely that this is located in jshint-eclipse. It could be a failure to rebuild on save (is Project > Build Automatically checked?) or some error with the input file (this should show up in the Eclipse Error view).

machineghost commented 11 years ago

Thanks for the response, but unfortunately in an attempt to resolve this issue I've since restarted with a fresh copy of Eclipse. However, I'm now I'm getting a new issue (a ClassCastException), which I filed here: https://github.com/eclipsesource/jshint-eclipse/issues/52

ralfstx commented 10 years ago

It seems that I can't do anything without being able to reproduce it. So I'm closing this issue now, please re-open when you have a reproducible setup.