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

Missing warning for: ReferenceError: variable is not defined #516

Open
knobo opened this issue Mar 7, 2019 · 9 comments
Open

Missing warning for: ReferenceError: variable is not defined #516

knobo opened this issue Mar 7, 2019 · 9 comments

Comments

@knobo
Copy link

knobo commented Mar 7, 2019

js2-mode should warn about "unused var0" and "var1 is not defined".

function missingWarning (var0) {
  const var1 = {var1};
  console.log("Var1:", var1);
}
missingWarning();
$ node ./missing-warning.jsx 
/tmp/missing-warning.jsx:82
  const var1 = {var1};
                ^

ReferenceError: var1 is not defined
@knobo
Copy link
Author

knobo commented Jul 11, 2019

And this one...

function destructme ({foo: bar}) {
  console.log('Foo contains: ', bar);
}
line 4: Variable 'bar' referenced but never initialized
line 5: Variable 'bar' referenced but never initialized

Maybe it should be a separate issue?
image

@dgutov
Copy link
Collaborator

dgutov commented Jul 26, 2019

@lelit It would be great if you could take a look.

@lelit
Copy link
Contributor

lelit commented Jul 27, 2019

Will do, and sorry for not noticing this kind of reports!

@lelit
Copy link
Contributor

lelit commented Aug 5, 2019

WRT the unused parameter, it's a deliberate behavior, given how often you write a function that does not consume all its arguments. Maybe there could be an opt-in/opt-out option to select a different reaction.

On the undefined var, it's indeed a general defect I will try to address, as it manifests itself even in a simpler case:

function foo() {
  var x = x + 1;
}

I seem to remember that the logic behind the check is "was this variable declared in var-block before this point?"... it should probably add the check "... and, if this is a declaration, a DIFFERENT var-block" or something like that.

@knobo
Copy link
Author

knobo commented Aug 5, 2019

About the unused parameter. It is in fact used, so why should it produce a warning?

image

This variable is destructured and given a new name, as documented here:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Assigning_to_new_variable_names

@lelit
Copy link
Contributor

lelit commented Aug 5, 2019

I was talking about the comment

js2-mode should warn about "unused var0" and "var1 is not defined".

in your first example:

function missingWarning (var0) {
  const var1 = {var1};
  console.log("Var1:", var1);
}
missingWarning();

@knobo
Copy link
Author

knobo commented Aug 5, 2019

Aha! My mistake. I suspect I did not get a warning about var0 in my editor when I created the example. I'm not sure but that warning might have been implemented after I created my example.

@knobo
Copy link
Author

knobo commented Aug 5, 2019

Yes that's right.. #515

@knobo
Copy link
Author

knobo commented Aug 22, 2019

This one is related:

image

  if (changed) {
    for (let [path, value] of Object.entries(changed)) {
      updated = _.set(path, value, updated);
    }
  }

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