New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSHint reports an implied global variable when it is not global #668

Closed
Sense545 opened this Issue Oct 3, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@Sense545
Copy link

Sense545 commented Oct 3, 2012

Running JSHint on this piece of code reports 'baz' as an implied global variable when it is not:

(function(){
    var foo = { bar: function() { baz(); } };
    function baz() { }
    foo.bar();
    baz();
}());
@goatslacker

This comment has been minimized.

Copy link
Member

goatslacker commented Oct 8, 2012

latedef: true rather than false.

Your code passes fine:

/*jshint strict: false, latedef: true*/
(function(){
  var foo = { bar: function() { baz(); } };
  function baz() { }
  foo.bar();
  baz();
}());

@goatslacker goatslacker closed this Oct 8, 2012

@Sense545

This comment has been minimized.

Copy link

Sense545 commented Oct 12, 2012

After some investigation i found the source of the warnings. It was in the reporter:

var globals = result.implieds;
if (globals) {
  globals.forEach(function (global) {
    for (var line in global.line){
      console.log(
        global.line[line] + ': \'' + global.name + '\' is an implied global variable.'
      );
    }
  });
}

So jshint does not warn, but treats and reports them as implied gobal variables when they are not

@valueof valueof reopened this Oct 12, 2012

@valueof

This comment has been minimized.

Copy link
Member

valueof commented Oct 12, 2012

Thanks, that looks like a bug.

@valueof valueof closed this in 077a0f3 Dec 18, 2012

jugglinmike added a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014

Clear implied variables even when undef is false.
We have a pretty hacky code that clears implied variables that
were defined later on. The problem is that code is called only
when the undef option is on. So this means that when it's off
JSHINT.data().implieds array can be populated with false positive
data.

This patch changes the code so that it always collects and
clears undefined variables but checks the undef option when
it's ready to warn.

Closes jshintGH-668.

danielctull pushed a commit to danielctull-forks/jshint that referenced this issue Jan 14, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment