Skip to content
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
Closed

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

Sense545 opened this issue Oct 3, 2012 · 3 comments
Milestone

Comments

@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
Copy link
Member

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();
}());

@Sense545
Copy link
Author

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
Copy link
Member

valueof commented Oct 12, 2012

Thanks, that looks like a bug.

jugglinmike pushed a commit to jugglinmike/jshint that referenced this issue Oct 21, 2014
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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants