2

JSHint is telling me that the value of local variable isInitOk is never read. But it is updated only if a $get success function runs and exposed with a method.

var my = function () {  
    var isInitOk = false;

    function discoverSuccess(rsp) { 
        ...     
        isInitOk = true;
    }

    function init() {
        ...
        $.get(config.serverURL, discoverSuccess, 'json');       
    }

    function assertInitOk() {
        return isInitOk;
    }

    return {
        assertInitOk: assertInitOk
    };
}();
Lurk21
  • 2,307
  • 12
  • 37
  • 55
  • 2
    Do you ever call `assertInitOk`? You're returning a reference to the function - not the output of it. – h2ooooooo Jan 09 '14 at 19:51
  • In another function outside this file, thus the exposure. It just seemed kind of strange to me. I guess returning it doesn't count as reading it. Seems like it should not warn on this if the variable is returned. – Lurk21 Jan 09 '14 at 19:54
  • 1
    It doesn't count as reading it as javascript (technically) have no idea what `assertInitOk` does until it actually executes the function. – h2ooooooo Jan 09 '14 at 19:56
  • I guess that's cool - just kind of puzzled me at first. – Lurk21 Jan 09 '14 at 19:58
  • 2
    @h2ooooooo It knows what that function does just fine, it just doesn't know how and when the function might be called and what names refer to it. However, all that is inconsequential because we're talking about *JSHint* which is a *static* analyzer that works on source code. –  Jan 09 '14 at 19:59
  • 3
    Does it point specifically to that second line of code? Putting that limited code you gave in jsHint doesn't produce that message. – cookie monster Jan 09 '14 at 20:00
  • @cookiemonster yup the second line - I'm using the jshint eclipse plugin if that matters. But I get it now - jshint's scope is just the one file and it doesn't see it's return function being used anywhere. I'll just turn a blind eye to it. Thanks all. – Lurk21 Jan 09 '14 at 20:07
  • 1
    It should still see that the variable is being used. Like I said, it doesn't give me that message. It does however if I remove that variable reference from the functions. – cookie monster Jan 09 '14 at 20:08
  • @cookiemonster I just tried it in the jshint web site and it did not flag the variable as unused. So just a problem with the eclipse plugin I guess. – Lurk21 Jan 09 '14 at 20:18
  • possible duplicate of [Prevent JSHint warning that 'functionName is defined but never used'](http://stackoverflow.com/questions/12607289/prevent-jshint-warning-that-functionname-is-defined-but-never-used) – Paul Sweatte Dec 20 '14 at 13:29
  • @Paul: They don’t want to *suppress* the warning; they want to know why the warning was emitted in the first place. As such, not a duplicate. – icktoofay Dec 22 '14 at 00:13

1 Answers1

0

@cookiemonster is correct, this is a bug in the Eclipse plugin unfortunately:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=351470

Dovev Hefetz
  • 1,346
  • 14
  • 21